Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1
fi

In tcsh, the if statement has two forms. The first form, similar to the one
for pdksh and bash, is as follows:


Click here to view code image
if (expression) then
Statements
else if (expression) then
Statements
Else
Statements
endif


Using the example of the variable var having only two values, Yes and No,
here is how it is coded with tcsh:


Click here to view code image
if ($var == "Yes") then
echo "Value is Yes"
else if ($var == "No" ) then
echo "Value is No"
else
echo "Invalid value"
endif


The second form of the if condition for tcsh is as follows:


Click here to view code image
if (expression) command


In this format, only a single command can be executed if the expression
evaluates to true.


The expr Statement


You use expr to evaluate an expression. It can evaluate numbers and
mathematic expressions. It can also be used to evaluate strings and perform
comparisons. Some examples follow.


To add or subtract, multiply or divide, use one of the following:


Click here to view code image
expr 12 + 2
expr 26-24
expr 6 * 3
expr 11 / 3

Free download pdf