[X-Unix] Shell Script: How get parent path to invoke a sister tool?

Eric F Crist ecrist at secure-computing.net
Fri May 23 11:55:01 PDT 2008


On May 23, 2008, at 1:32 PM, Stroller wrote:

>
> On 23 May 2008, at 15:21, Jerry Krinock wrote:
>
>> I want to ship someone a directory containing two files: a shell  
>> script and a tool.  Within the shell script, I'd like to invoke the  
>> tool.  And I want it idiot-proofed to work regardless of where the  
>> user drops my directory.
>>
>> So, I need the path to the tool within the script...
>
> $ touch foo.sh bar.sh
> $ echo '#!/bin/bash' > foo.sh
> $ echo '#!/bin/bash' > bar.sh
> $ echo 'echo "it worked!"' >> bar.sh
> $ echo "./bar.sh" >> foo.sh
> $ chmod +x *.sh
> $ ./foo.sh
> it worked!
> $
>
> In other words, the path to the current working directory is "./"
>
> Stroller.

His current working directory may not be . relative to the directory  
his script and tool reside in.  I think that's the rub.  dirname $0 I  
think is his best solution, aside from having his friend possibly put  
his script and/or tool somewhere within their PATH.

-----
Eric F Crist
Secure Computing Networks




More information about the X-Unix mailing list