GADDe

        sometimes you will never know the true value
        of a moment until it becomes a memory.

        Imah Abdulmajid (David Bowie's wife)

sh Scripting: Variables and Loops
---------------------------------

0.sh

  #!/bin/bash

  # Achtung! Aussenseiter Kode (ll. 4-8)
  case $RANDOM in
    '') echo "Do not run this by \$ sh $0 !!!" && \
        echo "\$ chmod +x $0" && \
        echo "\$ ./$0" && exit ;;
  esac

  MYVAR=123

  echo "my varible MYVAR has value $MYVAR"

  echo "\$0 = $0 - The name of the Bash script"
  echo "\$1 - \$9 - The first 9 arguments to the Bash script"
  echo "\$# = $# - How many arguments were passed to the Bash script"
  echo "\$@ = $@ - All the arguments supplied to the Bash script"
  echo "\$? = $? - The exit status of the most recently run process"
  echo "\$\$ = $$ - The process ID of the current script"

  echo "\$USER = $USER - The username of the user running the script"
  echo "\$HOSTNAME = $HOSTNAME - The hostname of the machine the script is running on"
  echo "\$SECONDS = $SECONDS - The number of seconds since process (bash) was started"
  echo "\$RANDOM = $RANDOM - Returns a different random number each time is it referred to"
  echo "\$LINENO = $LINENO - Returns the current line number in the Bash script"

1.sh

  #!/bin/bash
  # while demonstration

  x=1
  while [ $x -lt 10 ]
  do
    echo "x = $x"
    x=`expr $x \+ 1`
  done

2.sh

  #!/bin/bash
  # for demonstration

  for x in `seq 3 4 33`
  do
    echo "x = $x"
  done

3.sh

  #!/bin/bash
  # continue and if

  x=1
  while [ $x -lt 10 ]
  do
    echo "x = $x"
    x=`expr $x \+ 1`
    if [ $x -gt 5 ]
    then
      continue
    fi
    echo "blahblah"
  done

4.sh

  #!/bin/bash
  # break demonstration

  x=1
  while [ $x -lt 10 ]
  do
    echo "x = $x"
    x=`expr $x \+ 1`
    if [ $x -gt 5 ]
    then
      break
    fi
    echo "blahblah"
  done

Tips and Links:
---------------

  https://ubuntuforums.org/showthread.php?t=2091791
  You can just chmod +x script.file then ./script.file
  You defined bash in top line

  http://stackoverflow.com/questions/4277665
  /how-do-i-compare-two-string-variables-in-an-if-statement-in-bash
  For string comparison, use: if [ "$s1" == "$s2" ]

  http://stackoverflow.com/questions/3411048
  /unexpected-operator-in-shell-programming
  you can use case/esac instead of if/else
  case "$choose" in
    [yY]) echo "Yes" && exit;;
    [nN]) echo "No" && exit;;
    * ) echo "wrong input" && exit;;
  esac
