Sometime a script needs to now the directory that it is executing from, the best solution for this is:
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Although the simpler version below should work for most cases the version above is preferred for shell portability.
DIR=`dirname $0`
The usage of this could be for creating shell scripts that a user can double click to execute or drag on to the terminal to execute, as the working directory could change. Uses the scripts folder means that if a user copies the script to a new project it will work in the new project rather than having absolute paths to the old project.
1 2 3 4 5 6 7 8 9 10 11 | |