MLUG: Re: [MLUG] shell script - find shell script parent directory?
Re: [MLUG] shell script - find shell script parent directory?
Email address obfuscation in effect -- please click here to turn it off.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
On Mon, 3 Mar 2008, Robert Citek wrote:

On Sat, Mar 1, 2008 at 12:16 PM, Mike Miller <EMAIL:PROTECTED> wrote:
We had a fairly long discussion about this on TCLUG (Twin Cities) and I
 thought you guys also would find it interesting and informative.  It
 started with this question about bash scripting:

    I'm trying to find a variable or a command that will tell me where
    the currently executing script lives.

I'll take a stab:

$cat foo.sh
#!/bin/bash
echo $0

Although I suspect this is not what you are looking for.

Well, you are on the right track but we want the full path. Your method works if the full path was given on the command line or if the file was in the path (the latter fact surprised me). Examples where "echo $0" won't work:


./foo.sh
../local/bin/foo.sh

Mike

_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members