Reputation: 9355
I've my .sh script as
#!/bin/bash
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: sync.sh DIRECTORY_LOCATION"
exit 1
fi
DIRECTORY_LOCATION=$1
DEV_INSTANCE_IP=<some ip>
# Update data
scp -pR ${DEV_INSTANCE_IP}:${DIRECTORY_LOCATION}/* ${DIRECTORY_LOCATION}/
How do I run this script??
I tried sh sync.sh <path to directory>
but it echos the line Usage: sync.sh DIRECTORY_LOCATION
. Does that mean it's being run??
Upvotes: 0
Views: 214
Reputation: 3335
Ahem, the script requires a second (bogus = never used) argument in the condition || [ -z "$2" ]
if you delete that part, it should work as the authors meant it to be used, whatever this may be ;-)
At least it should work the way you called it, namely sh sync.sh <path to directory>.
And no, if you only provided this one argument in your version, it preinted the usage and exited undone.
You can also just provide a second argument (as long as you do not mix-up with the two, i.e. providing the directory as the second arg would not help ...
Upvotes: 1
Reputation: 45634
yes it's running, -z
flag means
-z STRING True if string is empty.
If either first argument or second is empty --> exit.
one way of getting more information is to change the shebang to #!/bin/bash -x
this will tell bash to print every line that is executed including the value of the parameters.
Upvotes: 1
Reputation:
The $1 in this script means it's expecting another entry for the DIRECTORY_LOCATION. So, you would need:
bash sync.sh directoryname
Also, instead of using sh scriptname.sh, it's better to do "chmod +x scriptname.sh".
Hope this helps!
Upvotes: 1