Saturday, 31 August 2013

Bash Script If null evaluating as false when true

Bash Script If null evaluating as false when true

I've run into my second hurdle in my journey into shell scripting. I
cannot seem to get my if statement to evaluate as true for a null value. I
am trying to pass an argument to the script and have the script let me
know if I am missing the required variable. Unfortunately it keeps falling
through to the else statement, even though it should be evaluating the
variable as a null one. Here is the script:
if [ "$1" == "d" ]; then
if [ -n "$2" ]; then
echo "Please enter the local location of the files"
else
LOCAL=$2
scp -r -i ~/Dropbox/Business/aws/first.pem $LOCAL
ubuntu@54.XXX.194.202:~/test/
fi
else
scp -r -i ~/Dropbox/Business/aws/first.pem
~/Dropbox/Business/aws/files/binaryhustle/
ubuntu@54.XXX.194.202:~/test/
fi
Here is the command I am running to execute the script:` bash copyfile.sh d
The response I get is:
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program] [[user@]host1:]file1 ...
[[user@]host2:]file2 `

No comments:

Post a Comment