Suresh Payankannur

Tuesday, July 26, 2011

Bash Tips

Debugging a bash script
% bash -x myscript.sh
Setting variables like CLASSPATH etc. using a script

Typically when setting variables with in a script and executing the script (% setenv.sh) makes these variables available only within the sub-process that executing the script. Once the script execution is done, these variables are not passed back to the parent shell. In order to achieve this, one has to 'source' it.

Suppose you have a shell script which contains the following line:
CLASSPATH="/opt/jars:/usr/lib/jars"
export CLASSPATH
In order for this variable to be available to the parent shell:
% source setenv.sh
Then the variable will be available in the parent shell
% env | grep -i classpath
Will show the set values.


0 comments:

Post a Comment

Blog Archive

Scroll To Top