I’m not sure how to do an if with multiple tests in shell. I’m having trouble writing this script:
echo "You have provided the following arguments $arg1 $arg2 $arg3"
if [ "$arg1" = "$arg2" && "$arg1" != "$arg3" ]
then
echo "Two of the provided args are equal."
exit 3
elif [ $arg1 = $arg2 && $arg1 = $arg3 ]
then
echo "All of the specified args are equal"
exit 0
else
echo "All of the specified args are different"
exit 4
fi
The problem is I get this error every time:
./compare.sh: [: missing `]’ command not found
shis interpreting the&&as a shell operator. Change it to-a, that’s[’s conjunction operator:Also, you should always quote the variables, because
[gets confused when you leave off arguments.