This or That ??

As we get different routes in the journey of life , we get different paths in the flow of our code , which to select depends on our logic , it may be right or wrong , but it depends on our conditions !!


if condition

if this is true then i would do that


Syntax 0:

 if condition
then

...
...
else
...

fi


Syntax 1:
           if condition
then
....

elif another_condition
then
....
else
....
fi


test command or [ expr ]

Am i a hero ?


If test returns zero then I am a hero , or else any non-zero value from the test clearly says I am not a hero.


Syntax:


test expression OR [ expression ]


Can be used on : Integer ,File types and Character strings .


Conditions :

eq
equal to
ne
not equal
gt
greater than
lt
lesser than
ge
greater than or equal
le
lesser than or equal

For strings we can use == and != , for equals and not equal to conditions.


For file we can use -[ s,f,d,w,r,x,] file , can be used to check ,non empty ,file,directory, wrx permissions respectivly.


Local operations like !,-a,-o i.e NOT,AND,OR can be used with expressions .



Case statement


Case in expression then go to the referred case number or the pattern


Syntax:

case expression in
pattern1) execute commands ;;
pattern2) execute commands ;;
...
esac
P.S : ";;" and ')'




Share this