bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: running source twice wont use arguments


From: Bernd Eggink
Subject: Re: running source twice wont use arguments
Date: Sat, 18 Oct 2008 10:44:48 +0200
User-agent: Thunderbird 2.0.0.17 (X11/20080914)

pgb schrieb:
I have a bash script that I run using source because I want to be left in the
environment that the script sets up after running the script. The script
takes a few arguments and sets up an environment for me that includes
library paths, classpaths, JAVA_HOME, appends to the PATH, creates and
populates a local workspace etc. I call the script in the following manner

source setup_env -o -w testdir

The -o argument is to wipe out the workspace if it already exists
(unconditionally) and the -w provides the name of the workspace to setup.
The first time I run the script it runs just fine and all the arguments work
as expected, the environment is all setup etc.

However, if I immediately run the command again all the arguments are
completely ignored

source setup_env -o -w testdir

The script runs but fails because it's not reading in the args for some
reason. As a matter of fact, if I give an argument that doesn't even make
sense (-garbage) , the script runs but again the arguments are ignored so it
ultimately fails.

I searched the forum but did not find a related post. If I don't source the
script and run it from the command line, it works both times, but then my
environment is not mantained after the script runs so that's not a good idea

What in my environment, post-script-run is making the second source not
"see" the command line arguments?

You probably use getopts, which changes the variable OPTIND in the current environment. The value of this variable is not automatically reset if you start another getopts loop, you have to do it yourself:

    OPTIND=1
    while getopts "ow:" opt
    do
       ...
    done

Regards,
Bernd

--
Bernd Eggink
http://sudrala.de




reply via email to

[Prev in Thread] Current Thread [Next in Thread]