sys.argv index out of range error

Miles semanticist at gmail.com
Thu Sep 13 17:00:59 EDT 2007


On 9/13/07, Brian McCann wrote:
> bootstrap.sh
> #!/bin/sh
> cd /home/workspaces
> export LANG="en_US.UTF-8"
>
> source init $1
> test.py $2
> #################################
>
> what's wrong with  the line "source init $1  ?

Assuming your /bin/sh is actually the Bourne-again shell, this excerpt
from the Bash manual explains what's happening ("source" is a synonym
for "."):

"""
. filename [arguments]
Read and execute commands from the filename argument in the current
shell context. [...] If any arguments are supplied, they become the
positional parameters when filename is executed. Otherwise the
positional parameters are unchanged.
"""

So "source [script] [args]" clobbers the parameters of the *current*
shell context.  So any of these should work:
* use "source init.sh" to use the same shell context;
* use "./init.sh $1" to use a new context; or
* save the needed parameters in other variables before clobbering them.

-Miles



More information about the Python-list mailing list