bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is there a special variable for the directory where the script is in


From: Marc Herbert
Subject: Re: Is there a special variable for the directory where the script is in?
Date: Fri, 12 Feb 2010 10:22:29 +0000
User-agent: Thunderbird 2.0.0.23 (X11/20090825)

pk a écrit :
> Peng Yu wrote:
> 
>> $0 gives the file name of the script. I could use several shell
>> command to get the directory where the script is in. But I'm wondering
>> if there is an easy-to-use variable that refers to the directory where
>> the script is in?
> 
> See this page:
> 
> http://mywiki.wooledge.org/BashFAQ/028

This is well informed, very useful and very interesting page is
considering the case where:

- you want your widely distributed and very portable script to be called
  in any way from anywhere (including from a pipe from Mars).
- hard-coding the location of your configuration files and libraries is
  not a problem.

I am sure this is the most common case. But this is definitely not my
case. Actually, my requirements are *the exact opposite*. For instance I
do not want anyone to use my script but me. So I just do this instead:

   source  $(dirname "$0")/functions.sh

The fact that it might break whenever someone else uses my script in a
way I did not plan is a feature (in this respect, this code is even too
robust).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]