Friday, February 1, 2013

Bash Conditionals

Conditionals are used when you must make some decision (to execute some part of code or not) by evaluating expression in your script.
For conditionals in Bash scripting language are used clauses: if, then, else.

if (some expression)
then
(do some code)
else
(do some code)

Simplest example is use only if,then

if ["$Var1" = "$Var2"]; then
echo "Variables Var1 and Var2 are equal!"
fi

with clause fi we close if statement.

Other example:

if ["$Var1" = "$Var2"]; then
echo "Variables Var1 and Var 2 are equal!"
else
echo "Variables Var1 and Var2 are NOT equal!"
fi


No comments:

Post a Comment