Reputation: 4559
Is there a way to get the script directory regardless of change in current directory that occurred during script execution.
echo $(dirname "$(readlink -f "$0")")
cd /tmp
echo $(dirname "$(readlink -f "$0")")
/home/user/test
/tmp
In the example above, I need /home/user/test
both times, without storing it to a variable.
Upvotes: 1
Views: 93
Reputation: 88999
This should do the job in your script:
dir="$(readlink /proc/$PPID/cwd)"
Upvotes: 1