Re: full path of a script
- From: Stephane CHAZELAS <this.address@xxxxxxxxxx>
- Date: Tue, 25 Sep 2007 13:16:12 GMT
2007-09-25, 15:01(+02), Joachim Schmitz:
[...]
~/bin$ print '#! /bin/bash -\nprintf "%s\\n" "$0"' > aHere too... and no contradiction to what I said. Or meant to say... if bash
~/bin$ chmod +x a
~/bin$ PATH= /bin/bash -c a
a
~/bin$ PATH=. /bin/bash -c a
./a
finds it somewhere in PATH, $0 contains an absolute pathname
First both (except for some old bogus versions of ksh) only
lookup the command in $PATH if the script name passed as
argument doesn't contain any slash and is not to be found in the
current directory. That's why I said it can only happen if you
call the shell interpreter directly as in "bash a" or "ksh a".
In that case, I find that both bash and ksh behave the same:
~$ PATH=~/bin /bin/ksh a
a
~$ PATH=~/bin /bin/bash a
a
, if it is in[...]
the current dir and that is part of PATH, it prints a relative name
ksh behaves different, here $0 expands to a relative path if it is found
somewhere in PATH and to a plain filename if it's found in the current
directory
I still don't see what you mean. I know some old versions of ksh
had a bug where it would search in $PATH before searching in the
current directory. Is that what you are refering to?
If not, could you please give an example?
[...]
You're right, I've looked it up in the source code, it's well hidden (and I[...]
missed it the first time), but it's indeed there... It doesn't seem
documented though
I beleive it is. And it's also how it is specified by POSIX, cd
is a short for "cd -L", same for pwd. In scripts using -L almost
never makes sense, so systematically adding -P is generally a
good idea.
--
Stéphane
.
- Follow-Ups:
- Re: full path of a script
- From: Joachim Schmitz
- Re: full path of a script
- References:
- [zsh] full path of a script
- From: Martin Krischik
- Re: full path of a script
- From: Miles
- Re: full path of a script
- From: Martin Krischik
- Re: full path of a script
- From: Joachim Schmitz
- Re: full path of a script
- From: Miles
- Re: full path of a script
- From: Joachim Schmitz
- Re: full path of a script
- From: Stephane CHAZELAS
- Re: full path of a script
- From: Joachim Schmitz
- Re: full path of a script
- From: Stephane CHAZELAS
- Re: full path of a script
- From: Joachim Schmitz
- [zsh] full path of a script
- Prev by Date: Re: full path of a script
- Next by Date: problem running cmd from ksh script
- Previous by thread: Re: full path of a script
- Next by thread: Re: full path of a script
- Index(es):