Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

a user can pass various options. Depending on the specified option, the
parameters that follow can mean different things or might not be there at all.


The format of the shift command is as follows:


shift       number

The parameter number is the number of places to be shifted and is optional.
If it is not specified, the default is 1 ; that is, the parameters are shifted one
position to the left. If it is specified, the parameters are shifted number
positions to the left.


The if Statement


The if statement evaluates a logical expression to make a decision. An if
condition has the following format in pdksh and bash:


Click here to view code image
if [ expression ]; then
Statements
elif [ expression ]; then
Statements
else
Statements
fi


if conditions can be nested. That is, an if condition can contain another if
condition within it. It isn’t necessary for an if condition to have an elif or
else part. The else part is executed if none of the expressions that are
specified in the if statement are true and are not evaluated if preceding
elif statements are true. The word fi is used to indicate the end of the
if statements, which is very useful if you have nested if conditions. In such
a case, you should be able to match fi to if to ensure that all if statements
are properly coded.


In the following example for bash or pdksh, a variable var can have either
of two values: Yes or No. Any other value is invalid. This can be coded as
follows:


Click here to view code image
if [ $var = "Yes" ]; then
echo "Value is Yes"
elif [ $var = "No" ]; then
echo "Value is No"
else
echo "Invalid value"

Free download pdf