argv[0] manipulation
Robin Munn
rmunn at pobox.com
Thu Dec 12 10:32:38 EST 2002
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?
Wait a minute, this Redhat 7.3 box over here, running ksh as the shell,
says differently:
[rmunn at localhost] /home/rmunn/bin> $ cat tryme.py
#!/usr/bin/python
import os, sys
print sys.argv
[rmunn at localhost] /home/rmunn/bin> $ ./tryme.py
['./tryme.py']
[rmunn at localhost] /home/rmunn/bin> $ tryme.py
['/home/rmunn/bin/tryme.py']
My PATH contains '/home/rmunn/bin' and does NOT contain '.'. Therefore I
conclude that ksh *does* prepend the appropriate dir to argv[0], and/or
that I must have misunderstood what you are saying. Explanations,
please?
>
>> Python does what it should with argv, copies it directly into sys.argv.
>
> Definitely agreed.
>
> Pádraig.
>
--
Robin Munn <rmunn at pobox.com>
http://www.rmunn.com/
PGP key ID: 0x6AFB6838 50FF 2478 CFFB 081A 8338 54F7 845D ACFD 6AFB 6838
More information about the Python-list
mailing list