Difference between revisions of "Bash if elif else fi"
From thelinuxwiki
Line 5: | Line 5: | ||
statement1 | statement1 | ||
statement2 | statement2 | ||
− | + | elif [ conditional expression2 ] | |
then | then | ||
statement3 | statement3 |
Revision as of 13:18, 16 April 2021
Bash If..elif..else..fi
if [ conditional expression1 ] then statement1 statement2 elif [ conditional expression2 ] then statement3 statement4 else statement5 fi
example
if [ "$opt" = "some string" ]; then some_command fi
OR example
<nowiki> if [[ "$VARIABLE" == "something" || "$VARIABLE" == "else" ]]; then</nowiki> some_command fi
conditional based on string compare
if a variable contains a string...
string='foobar' if [[ $string == *"bar"* ]]; then echo "your bar is in my foo!" fi