argv[0] manipulation

P_spam_ at draigBrady.com P_spam_ at draigBrady.com
Thu Dec 12 10:28:20 EST 2002


Robin Munn wrote:
> P_spam_ at draigBrady.com <P_spam_ at draigBrady.com> wrote:
> 
>>Donn Cave wrote:
>>
>>>Quoth P_spam_ at draigBrady.com:
>>>...
>>>| I had assumed that the shell passes what you type for executables
>>>| in the $PATH directly in argv[0]. This is silly of course and
>>>| it just passes appropriate_path_entry+'/'+what_you_type so you can't
>>>| distinguish from argv[0] whether a program was found in the $PATH
>>>| or explicitly specified by the user.
>>>
>>>Depends on the shell.  Bash and rc do one thing, ksh does another.
>>
>>Well I'll be darn diddley arned. tcsh does the same as ksh.
>>I.E. if the prog is found in $PATH then the appropriate dir
>>is not prepended to argv[0].
> 
> *Boggle*. Do you mean that tcsh and ksh, if "myscript.py" is found in
> $PATH, simply pass "myscript.py" as argv[0] instead of passing
> "/home/myusername/bin/myscript.py"? Then how am I supposed to, say,
> check for a config file in my script's directory? Or find the data file
> locations based on my script's location?

Yes that is a problem. I tried tcsh on RH7.3 and ksh on FreeBSD with
the same result (path is not prepended).

Pádraig.




More information about the Python-list mailing list