Re: Determinate the directory whithin a script
On 07/30/2006 03:39 PM, Michelle Konzack wrote:
LOCATION=$(dirname $(readlink /proc/$$/exe))
Greetings
Michelle Konzack
Systemadministrator
Tamay Dogan Network
Debian GNU/Linux Consultant
Michelle Konzack, it's August 11, 2006, and you posted a
message you created twelve days ago, which was response to a
post made nearly two *months* ago.
The original poster, Paolo Pantaleo, said this[0]:
I have a script in something like
/media/sda1/backup/script.sh
since sda1 could be also sda2 or anything, I want to determintate at
run-time what is the directory in which the script is located, how can
I do?
pwd doesn't work, since I cuold call the script from some other direcotry
He received several responses. However, I tried your advice
above, and determined that it *does not* return the correct
directory. The code you posted returns the directory name of
the bash executable "/bin"--not the directory for the script.
I'm using Debian 3.1, and from examining your signature, I
conclude that you are using Debian too--which means that you
didn't bother to test your advice before storing it on your
hard disk, and you didn't bother to check it in the eleven
days between 7/30/2006 and today.
However, the day after Paolo posted, a person named Cameron
Hutchison posted this response [1]:
Here's an unportable implementation dependent way:
script_dir=$(dirname $(readlink /proc/$$/fd/255))
This works, and it probably worked seven weeks ago, but you
didn't check if the answer had already been given before you
posted.
In addition, your signature is twelve lines long (three times
the recommended amount).
To sum up, you posted a twelve-day-old message containing one
line of false information and twenty lines of fluff as a
response to a seven week old message.
Michelle Konzack, goodbye.
[0]
http://article.gmane.org/gmane.linux.debian.user/247517/match=determinate+directory+whithin+script
[1]
http://article.gmane.org/gmane.linux.debian.user/247666/match=determinate+directory+whithin+script
Reply to: