-
Challenge 1: Write a function that takes two arguments and returns their sum.
-
Challenge 2: Write a function that takes a string as an argument and returns the length of the string.
-
Challenge 3: Write a function that takes an array of integers as an argument and returns the largest number in the array.
-
Challenge 4: Write a function that takes a directory path as an argument and lists all the files and subdirectories in the directory.
-
Challenge 5: Write a function that takes a filename as an argument and checks if the file exists. If it does, print "File exists", otherwise print "File does not exist".
-
If you don't use local, the variable will be created as a global variable, which can cause unintended consequences and potentially overwrite existing variables outside of the function. To avoid this, always use local to declare variables inside functions.
-
In Bash, the return value of a function is the exit status of the last command executed in the function. If you don't explicitly return a value from the function, it will return the exit status of the last command in the function. This can cause confusion and unexpected behavior if you're not careful. To properly handle return values from functions, use the return statement to explicitly return a value, and use the $? variable to capture the return value when calling the function.
Bash scripts related to every session of this tutorial will be stored in isolated branches named after their session name.
You can access the main code and the challenge answer key related to every session at their own branch.