I get full pathnames when I do this. You may have a different /bin/sh then I do. My /bin/sh is bash.
It is notoriously difficult to determine the pathname of a program from within the program. The exec() API allows anything to be passed as argv[0], so it is possible for a programmer to exec() a program with a completely misleading argv[0]. -----Original Message----- From: Linux on 390 Port [mailto:[EMAIL PROTECTED] Behalf Of McKown, John Sent: Thursday, May 29, 2008 11:58 AM To: [email protected] Subject: BASH: where did a script execute from? I thought that I could get this from $0. But in my tests, if the script is on the PATH and I invoke it just with its name, I get just its name in return. For example: PATH=/usr/local/bin /usr/local/bin/dd.sh contains: #!/bin/sh echo $0 I invoke via: $dd.sh result is dd.sh with no indication of where it came from. Even worse: cd /usr/local/bin mv dd.sh .. ln -s ../dd.sh temp.sh temp.sh results in: ../dd.sh I don't know that it was invoked by "temp.sh", so I can't do a which to find out where it is from. I want to know so that I can have some scripts in a subdirectory which are not on the PATH. I then have a symlink to the "driver script" which is on the PATH. The "driver script" needs to determine the directory that it actually came from (the regular file, not the symlink) so that it can change the PATH for the duration of the script in order to execute other program and scripts from that same directory. I'm likely missing something simple. I hope. Thanks. -- John McKown Senior Systems Programmer HealthMarkets Keeping the Promise of Affordable Coverage Administrative Services Group Information Technology The information contained in this e-mail message may be privileged and/or confidential. It is for intended addressee(s) only. If you are not the intended recipient, you are hereby notified that any disclosure, reproduction, distribution or other use of this communication is strictly prohibited and could, in certain circumstances, be a criminal offense. If you have received this e-mail in error, please notify the sender by reply and delete this message without copying or disclosing it. ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 __________________________________________________________________________________________________ CONFIDENTIALITY NOTICE: This email from the State of California is for the sole use of the intended recipient and may contain confidential and privileged information. Any unauthorized review or use, including disclosure or distribution, is prohibited. If you are not the intended recipient, please contact the sender and destroy all copies of this email. ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
