Thursday, April 01, 2010

readlink for better scripting

Fritz Thomas solves a common shell scripting problem for me: finding where your script lives. This script saved as ~/bin/x:

echo "$0"
readlink -f "$0"

With ~/bin in PATH produces:

$ cd ~/bin; ./x
$ cd; x

Just what I need! (Yes, quite an odd home directory.)

Do note the caveats for readlink(1).

Post a Comment