In general, there are two types of Bash scripts:
For the second type of scripts, it is useful to change to the directory where the script is stored. This can be done with the following command:
cd "$(dirname "$(readlink -f "$0")")"
This command runs 3 commands:
readlink -f "$0"determines the path to the current script (
dirnameconverts the path to script to the path to its directory
cdchanges the current work directory to the directory it receives from