Answer by MrYellow for Get path of current script when executed through a...
DIR=$( cd -- "$( dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || ${BASH_SOURCE[0]})" )" &> /dev/null && pwd )BASH_SOURCE works with source ./script.sh where $0 does notreadlink supports...
View ArticleAnswer by blackjacx for Get path of current script when executed through a...
In my case (on macOS) I had to use:DIR=$(cd "$(dirname "$(readlink "$0" || echo "$0")")" && pwd)This is because the symlink or the script behind can both be called by users. So in both cases...
View ArticleAnswer by Kevin Campion for Get path of current script when executed through...
readlink -f doesn't work for me, I've this mistake:readlink: illegal option -- fusage: readlink [-n] [file ...]But this works fine:DIR="$(dirname "$(readlink "$0")")"echo $DIR
View ArticleAnswer by user2108420 for Get path of current script when executed through a...
One small addition to the above script. The -P option to pwd follows symlinksDIR="$(cd "$(dirname "$0")"&& pwd -P)"
View ArticleAnswer by diyism for Get path of current script when executed through a symlink
one line:cd $(dirname $([ -L $0 ] && readlink -f $0 || echo $0))
View ArticleAnswer by Caleb for Get path of current script when executed through a symlink
Try this as a general-purpose solution:DIR="$(cd "$(dirname "$0")" && pwd)"In the specific case of the following symlinks, you could also do this:DIR="$(dirname "$(readlink -f "$0")")"
View ArticleGet path of current script when executed through a symlink
I have a utility consisting of a couple of directories with some bash scripts and supporting files that will be deployed to several machines, possibly in a different directory on each machine. The...
View Article
More Pages to Explore .....