Bash scripting

  • assign variable var_name=value
  • refer a variable $var_name
  • $0 - The name of the script.
  • $1 - $9 - Any command line arguments given to the script. $1 is the first argument, $2 the second and so on.
  • $# - How many command line arguments were given to the script.
  • $* - All command line arguments.

if statements:

if [ <some test> ]
then
  <commands>
else
  <another>
fi

while loop:

while [ <some test> ]
do
  <commands>
done

for loops:

# for value in {1..5}
for var in <list>
do
  <commands>
done