I would like to halt my shell script if the user is currently not the shell script directory. For example, I am on the folder
~/ and call the shell script
~/shell/script.sh, the shell script should print
You are not allowed to call this shell script from another folder other than its directory. But if I am on the folder
~/shell and call
./script.sh than the execution is allowed.
Why do you care what the
$PWDis? You can change directories in the script if it matters:
cd "$(dirname "$0")"
It is a very local aggressive/dangerous script, so I would like the user to be present on the folder paying more attention on it when it is running the script.