Re: PATH and $0

2006-08-14 Thread Stephane Chazelas
On Sat, Aug 12, 2006 at 01:51:12AM -0600, Bob Proulx wrote: > Stephane Chazelas wrote: > > [ -e "$cmd" ] || cmd=$(command -v -- "$cmd") || exit > > Bob Proulx wrote: > > > Of course using command as you have done will work for bash. > > > > "command" is a POSIX command. So will work with every P

Re: PATH and $0

2006-08-12 Thread Andreas Schwab
[EMAIL PROTECTED] (Bob Proulx) writes: >> 2- word splitting when IFS contains non-blank characters varies >> from one shell to the next, and in most implementations >> (including bash and AT&T ksh, it differs from the way the shell >> splits $PATH internally to look up a command ("/bin:" is "/bin"

Re: PATH and $0

2006-08-12 Thread Bob Proulx
Stephane Chazelas wrote: > [ -e "$cmd" ] || cmd=$(command -v -- "$cmd") || exit > Bob Proulx wrote: > > Of course using command as you have done will work for bash. > > "command" is a POSIX command. So will work with every POSIX and > therefore every Unix conformant sh. That is not strictly tru

Re: PATH and $0

2006-08-02 Thread Stephane Chazelas
On Thu, Jul 13, 2006 at 11:53:00PM -0600, Bob Proulx wrote: > Stephane Chazelas wrote: > > $0 will always contain the file path, unless the script was > > started as: > > > > bash script.sh > > > > And there's no script.sh in the current directory (in which case > > sh/bash will have looked up scr

Re: PATH and $0

2006-07-13 Thread Bob Proulx
Stephane Chazelas wrote: > $0 will always contain the file path, unless the script was > started as: > > bash script.sh > > And there's no script.sh in the current directory (in which case > sh/bash will have looked up script.sh in $PATH). Of course using command as you have done will work for ba

Re: PATH and $0

2006-07-12 Thread Cai Qian
Hi, On 7/12/06, Stephane Chazelas <[EMAIL PROTECTED]> wrote: On Tue, Jul 11, 2006 at 08:19:34PM -0400, Dave Rutherford wrote: > On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: > >I want its full pathname using 'dirname', but it will give me > >unexpected result on some Linux or Bash versions. >

Re: PATH and $0

2006-07-12 Thread Stephane Chazelas
On Tue, Jul 11, 2006 at 08:19:34PM -0400, Dave Rutherford wrote: > On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: > >I want its full pathname using 'dirname', but it will give me > >unexpected result on some Linux or Bash versions. > > Well, 'dirname' certainly won't do what you want, but I'm sor

Re: PATH and $0

2006-07-11 Thread Dave Rutherford
On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: I want its full pathname using 'dirname', but it will give me unexpected result on some Linux or Bash versions. Well, 'dirname' certainly won't do what you want, but I'm sorry, I can't think of a way to get what you need. (It would be relatively

Re: PATH and $0

2006-07-11 Thread Cai Qian
Hi, I want its full pathname using 'dirname', but it will give me unexpected result on some Linux or Bash versions. Qian On 7/11/06, Dave Rutherford <[EMAIL PROTECTED]> wrote: On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: > In some Linux, it will print "/tmp/script.sh", while in other, it wi

Re: PATH and $0

2006-07-11 Thread Dave Rutherford
On 7/11/06, Cai Qian <[EMAIL PROTECTED]> wrote: In some Linux, it will print "/tmp/script.sh", while in other, it will print "script.sh" only. Which is wrong? If both are fine, is there any better way to make it portable? Which do you want? (Both are fine.) If you want 'script.sh', use 'basen

PATH and $0

2006-07-11 Thread Cai Qian
Hi, What is the expected result of the following script? #! /bin/bash - export PATH=/tmp/ echo $0 exit 0 Then, put this file to /tmp/. cd / and run PATH=/tmp/ script.sh In some Linux, it will print "/tmp/script.sh", while in other, it will print "script.sh" only. Which is wrong? If both are