Reputation: 135
I am very new to Unix and this is one of my first scripts. I cannot seem to resolve this bad number error, and have searched for an answer online. I have not had much luck so I though I would turn here. Can someone help me out, I keep getting this :bad number error for both variables. Here is my script, thanks!:
#!/bin/ksh
dest=$1
fileName=$2
id=$$
print_message()
{
message="$1"
echo "`date '+%m-%d-%y %T'` $message"
}
if [ $1 -eq "" ] || [ $2 -eq "" ]
then
print_message "Parameters not satisfied"
exit 1
fi
gpg --encrypt --recipient "$dest" "$fileName"
print_message "$id INFO: File Encrypted Successfully"
Upvotes: 0
Views: 9440
Reputation: 24
It's because you've user -eq
which is meant for numerical values. You need to use =
for strings. Your code should look like this:
#!/bin/ksh
dest=$1
fileName=$2
id=$$
print_message()
{
message="$1"
echo "`date '+%m-%d-%y %T'` $message"
}
if [ $1 = "" ] || [ $2 = "" ]
then
print_message "Parameters not satisfied"
exit 1
fi
gpg --encrypt --recipient "$dest" "$fileName"
print_message "$id INFO: File Encrypted Successfully"
Easy mistake to make :)
Upvotes: 0
Reputation: 882226
Your problem lies here:
if [ $1 -eq "" ] || [ $2 -eq "" ]
Use =
instead of -eq
, the latter is meant for numbers rather than strings.
You may also need to wrap quotes around the possibly empty arguments, such as "$1"
.
Upvotes: 1