Functions loops and conditionals
Functions:
Initialize function via function_name (){} or function function_name { commands; } then use $1, $2, $3 etc. to access the arguments inside the function.
Loops and conditionals:
Loops will rerun a set of commands until a particular situation is reached. If statements decide whether or not to run a piece of code based on set conditions. Combine loops and if statements for more complex scrips solving larger tasks
For Loop:
- the for loop executes a set of commands for each item in a given list
for var in <list>
do
<commands>
done
While Loop:
- while expression evaluates as true a while loop will continue to execute
while [<some tests>]
do
<commands>
done
Until Loop:
- commands will be executed until statement evaluates as true
until [<some tests>]
do
<commands>
done