So, I'm learning some bash, and I'm trying to figure out how to get a script directory. Therefore, given that I have my script ~/scripts/bash/myscript, if I execute my script, for example:
user@localhost ~/dir/I/need/to/run/the/script/from $ ~/scripts/bash/myscript
from my script, how can I get the directory from which it is running, so I get ~/dir/I/need/to/run/the/script/fromin this case. Shortcuts like:
DIR=`pwd`
DIR="$(cd "$(dirname "$0")" && pwd)"
DIR=`dirname $0`
as far as I can see, they all assign the path to the script to DIR, but I'm looking for the path from which the script was run.
Any help on this?
Thank!!:)
source
share