I run in trouble resolving the full path of an sh (not bash) script or better, I want an "universal" sh function that resolve a path. I always used the following code to resolve a script path and always worked:
it works. Now I symlinked the script (relative symlink) in another directory. The directory of the symlink is
now the code line above no more works, I have to do
I'm looking for a solution for absolute and relative symlinks
EDIT
An "universal" function for symlinks (relative and absolute) and real path (not symlinked)
Bash:
sScriptDir="$( realpath $( dirname $0 ) )
/linkdir, the script is in the directory linkdir/scripts (names are fictional)
Code:
cd /linkdir
ln -s ./scripts/myscript.sh myscript
Bash:
s1="$( realpath $( dirname $0 ) )"
s2="${s1}/$( readlink $0 )"
s3="$( realpath $s2 )"
# show result
echo "\$s1 '${s1}'"
echo "\$s2 '${s2}'"
echo "real: '${s3}'"
I'm looking for a solution for absolute and relative symlinks
EDIT
An "universal" function for symlinks (relative and absolute) and real path (not symlinked)