Basic If Statements
#!/bin/bash # Basic if statement if [ $1 -gt 100 ] then echo Hey that\'s a large number. pwd fi date
If Else
#!/bin/bash # else example if [ $# -eq 1 ] then nl $1 else nl /dev/stdin fi
If Elif Else
#!/bin/bash # elif statements if [ $1 -ge 18 ] then echo You may go to the party. elif [ $2 == 'yes' ] then echo You may go to the party but be back before midnight. else echo You may not go to the party. fi
Boolean Operations
#!/bin/bash # and example if [ -r $1 ] && [ -s $1 ] then echo This file is useful. fi
#!/bin/bash # or example if [ $USER == 'bob' ] || [ $USER == 'andy' ] then ls -alh else ls fi
Multiple logical operators, ((A || B) && C)
use double brackets
if [[ ($A -eq 0 || $B -ne 0) && $C -eq 0 ]]; then …
References
https://ryanstutorials.net/bash-scripting-tutorial/bash-if-statements.php
https://unix.stackexchange.com/questions/290146/multiple-logical-operators-a-b-c-and-syntax-error-near-unexpected-t