1

I am trying to understand what dose the -o mean in the following bash if script.

looking at the results I can guess what it does but I do really need to get the concept of it.

i=1 for day in Mon Tue Wed Thu Fri Sat Sun do echo -n "Day $((i++)) : $day" if [ $i -eq 7 -o $i -eq 8 ]; then echo " (WEEKEND)" continue; fi echo " (weekday)" done 

The results are as following:

$ ./for7.sh Day 1 : Mon (weekday) Day 2 : Tue (weekday) Day 3 : Wed (weekday) Day 4 : Thu (weekday) Day 5 : Fri (weekday) Day 6 : Sat (WEEKEND) Day 7 : Sun (WEEKEND) 
2
  • 1
    As it is used there, it means || (OR). e.g. $i -eq 7 OR $i -eq 8. It can also be used to test whether an option set by set is set... (that's a lot of sets). That is why you are better off using [ "$i" -eq 7 ] || [ "$i" -eq 8 ] (note: always quote your variables with [...]) Commented Nov 7, 2017 at 4:05
  • If you use bash then [ is a builtin command. See: help test. Commented Nov 7, 2017 at 4:47

1 Answer 1

2

The -o symbolizes Logical OR here.

Do man test which explains this.

 EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.