Reliable way for a bash script to get the full path to itself? - Stack Overflow
I'm surprised that the realpath
command hasn't been mentioned here. My understanding is that it is widely portable / ported.
Your initial solution becomes:
SCRIPT=`realpath $0` SCRIPTPATH=`dirname $SCRIPT`
And to leave symbolic links unresolved per your preference:
SCRIPT=`realpath -s $0` SCRIPTPATH=`dirname $SCRIPT`
Read full article from Reliable way for a bash script to get the full path to itself? - Stack Overflow
No comments:
Post a Comment