Basic Shell Scripting Syntax Unix…Essentials

Just wanted to post very basic shell scripting essentials:

Basic Shell Scripting Concepts:

Arithmetic Evaluation (op refers to Operation):

let answer=var1 OP var2; echo $answer;
echo `expr var1 OP var2`

For … loop:

for file in x
do
    {body}
done
[x can be numbers, letters, paths etc]



If….then:

if  [ expression ]
then
   {body}
elif [ expression ]
then
   {body}
else
   {body}
fi

case:

case "VAR" in
   Result1)     {body}
   ;;
   Result2)    {body}
   ;;
   *)    {body}
   ;;
esac

do….while:

while  condition
do
   {body}
done

until…..do:

until condition
do
   {body}
done

Leave a comment

Your comment

CAPTCHA
*