<aside> ❗ Assignment 1 has came out, try to work on it little by little every day and don’t leave it last minute. It might take a bit of time to understand what you have to do before you can jump into coding.

</aside>

Useful commands to analyse how give works:

🔀 Shell case statements


Case statements is another way to write if statements.

Format:

case "$word" in
   pattern1)
      Statement(s) to be executed if pattern1 matches
      ;;
   pattern2)
      Statement(s) to be executed if pattern2 matches
      ;;
   pattern3)
      Statement(s) to be executed if pattern3 matches
      ;;
   *)
     Default condition to be executed
     ;;
esac

⚙️ Shell functions


Functions allow us to minimise repeated code.

Format:

function_name() {
	<commands>
}

Note that we don’t need to specify the arguments like in other programming languages.

We can refer to the arguments passed into a function by using $1, $2, and so on…

<aside> ⚠️ All variables declared in a function are global scope.

var='hi'
my_function() {
	var='hello'
}

echo "$var" // hi
my_function // This is how you run a function
echo "$var" // prints 'hello'

</aside>