Lo

for

Expand words, and execute commands once for each member in the resultant list, with name bound to the current member.

SYNTAX
for name [in words ...]; do commands; done
If `in words' is not present, the for command executes the commands once for each positional parameter that is set, as if `in " $@"' had been specified (see Positional Parameters below.)
The return status is the exit status of the last command that executes. If there are no items in the expansion of words, no commands are executed, and the return status is zero. An alternate form of the for command is also supported:
for (( expr1 ; expr2 ; expr3 )) ; do commands ; done
First, the arithmetic expression expr1 is evaluated according to shell arithmetic expression rules. The arithmetic expression expr2 is then evaluated repeatedly until it evaluates to zero.

Each time expr2 evaluates to a non-zero value, commands are executed and the arithmetic expression expr3 is evaluated. If any expression is omitted, it behaves as if it evaluates to 1.

The return value is the exit status of the last command in list that is executed, or false if any of the expressions is invalid.

Positional Parameters
These are assigned from the shell's arguments when the shell is invoked, they can be reassigned using the set builtin command.
Positional parameter N may be referenced as ${N}, or as $N when N consists of a single digit. $1, $2 etc

Example

#! /bin/bash# List of manufacturersfor m in Apple Sony Panasonic "Hewlett Packard" Nokiado echo "Manufacturer is:" $mdone


# The above could also be written as a single line...
for m in Apple Sony Panasonic "Hewlett Packard" Nokia; do echo "Manufacturer is:" $m;done
____________________________________________________________________________________________________________

case

Conditionally perform a command, case will selectively execute the command-list corresponding to the first pattern that matches word.


SYNTAX
case word in [ [(] pattern [| pattern]...) command-list ;;]... esac
The `|' is used to separate multiple patterns, and the `)' operator terminates a pattern list. A list of patterns and an associated command-list is known as a clause. Each clause must be terminated with `;;'.

The word undergoes tilde expansion, parameter expansion, command substitution, arithmetic expansion, and quote removal before matching is attempted. Each pattern undergoes tilde expansion, parameter expansion, command substitution, and arithmetic expansion. There may be an arbitrary number of case clauses, each terminated by a `;;'. The first pattern that matches determines the command-list that is executed.

Here is an example using case in a script that could be used to describe one interesting feature of an animal:
echo -n "Enter the name of an animal: "
read ANIMAL
echo -n "The $ANIMAL has "
case $ANIMAL in
horse | dog | cat) echo -n "four";;
man | kangaroo ) echo -n "two";;
*) echo -n "an unknown number of";;
esac
echo " legs."
The return status is zero if no pattern is matched. Otherwise, the return status is the exit status of the command-list executed.
____________________________________________________________________________________________________________

eval

Evaluate several commands/arguments

SYNTAX
eval [arguments]
The arguments are concatenated together into a single command, which is then read and executed, and its exit status returned as the exit status of eval. If there are no arguments or only empty arguments, the return status is zero.

eval is a POSIX `special' builtin
____________________________________________________________________________________________________________

if

Conditionally perform a command.

SYNTAX
if test-commands; then
consequent-commands;
[elif more-test-commands; then
more-consequents;]
[else alternate-consequents;]
fi
The test-commands list is executed, and if its return status is zero, the consequent-commands list is executed.

If test-commands returns a non-zero status, each elif list is executed in turn, and if its exit status is zero, the corresponding more-consequents is executed and the command completes.

If `else alternate-consequents' is present, and the final command in the final if or elif clause has a non-zero exit status, then alternate-consequents is executed.

The return status is the exit status of the last command executed, or zero if no condition tested true.
____________________________________________________________________________________________________________

while

Execute consequent-commands as long as test-commands has an exit status of zero

SYNTAX
while test-commands; do consequent-commands; done
The return status is the exit status of the last command executed in consequent-commands, or zero if none were executed.
____________________________________________________________________________________________________________

until

Execute consequent-commands as long as test-commands has an exit status which is not zero.

SYNTAX
until test-commands; do consequent-commands; done
The return status is the exit status of the last command executed in consequent-commands, or zero if none was executed.

comment 0 comments:

Popular Posts

Linux Gazette