Home » Questions » Computers [ Ask a new question ]

Folder where bash script resides when running via ln -s

Folder where bash script resides when running via ln -s

In /usr/local/bin I have a 'ln -s' to /usr/local/foo/bash.script, and in this latter script I want to know the current /usr/local/foo directory, so that I can run a secondary script from that folder.

Asked by: Guest | Views: 33
Total answers/comments: 1
Guest [Entry]

"try readlink, e.g.

d=$0

while readlink $d >/dev/null; do
d=`readlink $d`
done
echo $d

EDIT:

I am not sure if that works on other Unix OS, but if you are on linux the above can be simplified by using

d=`readlink -f $0`

echo $d

see

readlink --help"