Unix Shell - Re: full path of a script

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > September 2007 > Re: full path of a script





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: full path of a script
Stephane CHAZELAS

2007-09-25, 1:26 pm

2007-09-25, 15:01(+02), Joachim Schmitz:
[...]
> Here too... and no contradiction to what I said. Or meant to say... if bash
> 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
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com