Revision [539]

This is an old revision of HowToConditional made by DavidLee on 2009-05-21 18:58:21.

 

How To test a condition


Conditions can be tested with either the boolean operations "
" and "&&" or with the the if/elif/else/then clauses.

Boolean Operations


If you only need execute a single command or a small block then boolean operations are the easiest way

for example

if "command" returns successfully then print "is success"

$ command && echo is success


If the file "myfile.txt" exists then read the first line from the file and print it.

$ [ -e myfile.txt ] && { read VAR < myfile.txt ;  echo $VAR ; }



Structured Conditionals (if / elif / else / fi )


If the condition or conditional operations are more complicated then the structured conditionals are more useful.
This is the if / elif / else / fi construct.

The general form is
if  condition1 ; then 
   condition1 commands
elif  condition2 ; then
   condition2 commands
else 
   otherwise commands
fi





There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki