mercredi 3 février 2016

Ambiguous redirect in a Unix Shell Script with if-elif-else statement

I've just begun writing if-else statements in Unix. This is a short Bash script I recently wrote. I keep getting an ambiguous redirect error, however I can't figure out the problem.

When executed, I get the following error message:

stringComp: line 17: $str2: ambiguous redirect
stringComp: line 20: $str2: ambiguous redirect
stringComp: line 23: [: too many arguments

Here is the script:

str1="I like turtles"
str2="I want to be Iron Man"

if [ $str1 > $str2 ]
then
        echo "The first string is longer than the second"
elif [ $str1 < $str2 ]
then
        echo "The second string is longer than the first"
elif [ $str1 = $str2 ]
then
        echo "Both strings are of equal length"
else
        echo "Invalid argument"
fi

Any advice on what to do here? Thanks.

Aucun commentaire:

Enregistrer un commentaire