This question already has answers here:
Getting "command not found" error in bash script
(6 answers)
Closed 3 years ago.
I have this shell script
#!/bin/sh
PATHS=( a b c d )
for PATH in ${PATHS[#]}
do
rsync -avziP /home/user/$PATH $SERVER:$server_folder -b --backup-dir=$backup_folder/backup_$date --delete --exclude=.* --log-file=$HOME/rsync.log
done
And I always get this error:
rsync: command not found
What is driving me crazy is that if I delete the for loop, and just run the rsync command, the script works perfectly
PATH is a reserved variable!
It is the variable specifying where to search tools (like rsync)
$ set | grep ^PATH=
PATH=/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Use another variable name!
Related
This question already has answers here:
bash script execute command with double quotes, single quotes and spaces
(2 answers)
How to execute a bash command stored as a string with quotes and asterisk [duplicate]
(5 answers)
Closed 1 year ago.
I have a script to output git commits with specific jira ticket and within a date and time range, however i keep hitting an error, my codes are below:
SINCE="2021-02-26 17:59:58"
BEFORE="2021-03-05 17:59:58"
CMD="git log -p -m -name-status --since=\"${SINCE}\" --before=\"${BEFORE}\" --grep=${TICKET}
${CMD} >> out.txt
Error:
Fatal: Invalid object name '17'
I tried enclosing the cmd with "" "${CMD}" also getting same error.
Anyone know what is wrong with it?
This question already has answers here:
How to read a file into a variable in shell?
(9 answers)
Difference between sh and Bash
(11 answers)
Closed 4 years ago.
I have store ip address with port in a file and I want to read it using shell script. Thus file serverIP has data 192.168.1.17:3000. I am using following bash script to read it
IPAddressFile=/home/geo/serverIP
SERVER_IP_PORT=$(<$IPAddressFile)
echo $SERVER_IP_PORT
But this script echo empty string. Where I am making mistake?
If you're going to use bash-only syntax like $(<...), your script must be run with bash, not sh.
Thus, either run bash yourscript or add a #!/bin/bash (or similar) shebang, flag the file executable, and invoke it as a command, for example ./yourscript
As an alternative that's both efficient and compatible with POSIX sh:
IFS= read -r SERVER_IP_PORT <"$IPAddressFile"
This question already has answers here:
Command not found error in Bash variable assignment
(5 answers)
Run bash commands from txt file
(4 answers)
Closed 5 years ago.
I have a script shell that is reading from a file. This is the command line text that i would like to run under the bin folder of neo4j
bin/neo4j-import --into /home/micmal/neo4j-community-3.0.1/data/databases/graph_test.db --id-type string --nodes:
I would like to use a script shell to get that command and go to the folder of neo4j and paste it so it runs.
my shell looks like :
#!/bin/bash
batch_import_value= `cat _batchfile.txt`
cd /home/neo4j-community-3.0.1/
echo $batch_import_value`
it doesn't seem work
Any idea?
This question already has an answer here:
I got 'syntax error: "(" unexpected' (expecting "done") [duplicate]
(1 answer)
Closed 7 years ago.
Maybe I'm being really silly here but I can't seem to figure this out:
#!/usr/bin/env bash
...
DELTAS=($(ls -p /foo/bar/ | grep -P '^\d+[^\.]+\.sh$'))
...
If I run this interactively it's fine, and echo $DELTAS returns:
1-foo.sh
2-bar.sh
However, when this is run inside a bash script, I receive Syntax error: "(" unexpected; any ideas?
I'm guessing that you've not put #!/bin/bash at the top of your script, and so it's running using /bin/sh rather than /bin/bash. This would run under dash rather than bash on Ubuntu, for example.
That syntax is a bash extension.
This question already has answers here:
Getting "command not found" error in bash script
(6 answers)
Closed 3 years ago.
I have this shell script
#!/bin/sh
PATHS=( a b c d )
for PATH in ${PATHS[#]}
do
rsync -avziP /home/user/$PATH $SERVER:$server_folder -b --backup-dir=$backup_folder/backup_$date --delete --exclude=.* --log-file=$HOME/rsync.log
done
And I always get this error:
rsync: command not found
What is driving me crazy is that if I delete the for loop, and just run the rsync command, the script works perfectly
PATH is a reserved variable!
It is the variable specifying where to search tools (like rsync)
$ set | grep ^PATH=
PATH=/home/user/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Use another variable name!