sys.argv index out of range error

Ian Clark iclark at mail.ewu.edu
Thu Sep 13 17:06:40 EDT 2007


Brian McCann wrote:
> init.sh
> 
> #!/bin/sh
> WORKSPACE_ROOT="$1";
> 
> export JAVA_OPTIONS="-Djava.library.path=$WORKSPACE_ROOT/:$WORKSPACE_ROOT/:$WORKSPACE_ROOT/"
> echo "JAVA_OPTIONS="$JAVA_OPTIONS;
>  
> set PATH="$WORKSPACE_ROOT/vendor/basistech/rlp5.4/rlp/bin/ia32-glibc23-gcc32:$WORKSPACE_ROOT/vendor/basistech/rlp5.4/rlp/bin/ia32-w32-msvc71:$WORKSPACE_ROOT/lib/core:$PATH"

Taken from `help set` (at the bottom of the page; emphasis mine):
   Using + rather than - causes these flags to be turned off.  The
   flags can also be used upon invocation of the shell.  The current
   set of flags may be found in $-.  *The remaining n ARGs are positional
   parameters and are assigned, in order, to $1, $2, .. $n.  If no
   ARGs are given, all shell variables are printed.*

Short answer: change set to export.

Slightly longer answer:
What this invocation of set is doing is setting the shell variable PATH 
to the value you give *and* setting the $1 variable to the same value 
and removing all other numbered variables. So if you put a print $2 
after `source init.sh $1` in bootstrap.sh you'll notice it's blank, as 
set is removing it.

The reason this happens when you source the file rather than just 
calling it is that when you source a file it runs in the current shell. 
So calling set then wipes out all the other numbered variables. When 
simply calling the script it creates a subshell where those things still 
happen, just not in the parent shell.

Ian




More information about the Python-list mailing list