Jump to Navigation

200 - Bash if statement conditions

1. and, or

You can use "-a" or "&&" for and and "-o" or "||"for or

if [ [ condition 1] -a [ condition 2] ]; then
  [ Execute if both are true. ]
fi
if [ [ Condition 1] -o [ Condition 2] ]; then
  [ Execute if either is true. ]
fi

* Sample

bash$ if [ -d /opt -a -d /usr ]; then echo "TRUE"; else echo "FALSE"; fi
TRUE

bash$ if [ -d /foo -o -d /usr ]; then echo "TRUE"; else echo "FALSE"; fi
TRUE

 

 

Shell Script:


Main menu 2

Story | by Dr. Radut