1

Here is my statements:

print "Ss $# $2" >&3
if [ $# -eq 4 || $# -eq 3 ] && [ $2 != "d" ]
then
        print "sss"
else
        print "lol"
fi

The output is:

Ss 4 s
lol

Why is "sss" not being displayed?

0

1 Answer 1

4

Your if-condition isn't syntactically correct. You can't have || inside the brackets. Change it to use -o instead:

if [ $# -eq 4 -o $# -eq 3 ] && [ $2 != "d" ]
then
        print "sss"
else
        print "lol"
fi

Or, even better, use [[ (if your shell supports it) which is safer and has more features. It supports ||:

if [[ ( $# -eq 4 || $# -eq 3 ) && $2 != "d" ]]
then
        print "sss"
else
        print "lol"
fi
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.