<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>
watch -n1 tree -a
Can be used to monitor and display changes in all files within a directory in real-time.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
last.sh
that, using shell case statements, finds the number of loggins that occurred from within UNSW.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>
top_and_bottom.sh
that, given a file name, prints the file name, plus the first and last lines of the file.print_message.sh