Asked • 05/21/19

How to do a logical OR operation in Shell Scripting?

I am trying to do a simple condition check, but it doesn't seem to work. If `$#` is equal to `0` or is greater than `1` then say hello. I have tried the following syntax with no success: if [ "$#" == 0 -o "$#" > 1 ] ; then echo "hello" fi if [ "$#" == 0 ] || [ "$#" > 1 ] ; then echo "hello" fi

Anthony B.

Square brackets and || for sure, as in the latter syntax you mentioned. In Bash you would need to get rid of the "" around $#. What shell are you using (echo $SHELL)?
Report

05/26/19

1 Expert Answer

By:

Rize S. answered • 03/23/23

Tutor
New to Wyzant

Senior IT Certified Trainer, IT Developer & DBA Administrator

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.