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

2010-02-12 Thread Marc Herbert
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:

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

2010-02-12 Thread Guillaume Outters
Marc a écrit : source $(dirname $0)/functions.sh I usually begin all my scripts with this beast: absolutiseScripts() { SCRIPTS=$1 ; echo $SCRIPTS | grep -q ^/ || SCRIPTS=`dirname $2`/$SCRIPTS ; } ; absolutiseScripts `command -v $0` `pwd`/. ; while [ -h $SCRIPTS ] ; do absolutiseScripts

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

2010-02-12 Thread Greg Wooledge
On Fri, Feb 12, 2010 at 11:56:49AM +0100, Guillaume Outters wrote: I usually begin all my scripts with this beast: absolutiseScripts() { SCRIPTS=$1 ; echo $SCRIPTS | grep -q ^/ || SCRIPTS=`dirname $2`/$SCRIPTS ; } ; absolutiseScripts `command -v $0` `pwd`/. ; while [ -h $SCRIPTS ] ; do

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

2010-02-12 Thread Guillaume Outters
Greg a écrit : Except that HP-UX 10.20 and HP-UX 11.11 don't have readlink(1). (Maybe it's added in 11.2x? I don't know.) You're right. I must admit I made a concession to some GNU coreutils tools on the platform. I once used some ls -l $SCRIPTS | sed -e 's/.* - //' magic to replace it (and

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

2010-02-12 Thread Bob Proulx
Greg Wooledge wrote: That leaves names which contain -. The tricky part here is that we can't easily tell whether an extra - is in the symbolic link or in the target. imadev:~$ ln -s tmp 'x - y' imadev:~$ ln -s 'y - tmp' x imadev:~$ ls -ld x* lrwxr-xr-x 1 wooledgpgmr 8

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

2010-02-12 Thread Bernd Eggink
Am 12.02.2010 15:39, schrieb Greg Wooledge: On Fri, Feb 12, 2010 at 02:53:39PM +0100, Bernd Eggink wrote: I once wrote a more generic shell function for this purpose, see: http://sudrala.de/en_d/shell-getlink.html You note that it doesn't handle names containing -, which is true. I'll get

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

2010-02-12 Thread Andreas Schwab
Greg Wooledge wool...@eeg.ccf.org writes: And testing: imadev:~$ file=$HOME/x imadev:~$ link=$(command ls -l -- $file; printf x) imadev:~$ link=${link%$'\nx'} imadev:~$ remove=$file - imadev:~$ file=${link#*$remove} This lacks a pair of quotes (${link#*$remove}).

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

2010-02-11 Thread Peng Yu
$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?

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

2010-02-11 Thread Chris F.A. Johnson
On Fri, 12 Feb 2010, 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? $0 normally gives the full

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

2010-02-11 Thread pk
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:

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

2010-02-11 Thread Eric Blake
According to Chris F.A. Johnson on 2/11/2010 4:23 PM: On Fri, 12 Feb 2010, 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

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

2010-02-11 Thread Chris F.A. Johnson
On Thu, 11 Feb 2010, Eric Blake wrote: According to Chris F.A. Johnson on 2/11/2010 4:23 PM: On Fri, 12 Feb 2010, 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