Solved

edit CLASSPATH in .bashrc from schell script

Posted on 2006-11-02
5
1,035 Views
Last Modified: 2013-12-26
I'm writing a shell script in which I want to append variable to my classpath in my .bashrc file.  Is there an easy way to do this?
0
Comment
Question by:ICPooreman
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
cjjclifford earned 500 total points
ID: 17859913
If you mean you want the classpath ammended for the lifetime of the script itself, simple:

#!/bin/bash
export CLASSPATH=$CLASSPATH:my.jar
echo classpath is changed to $CLASSPATH

However, if you want to run a script, and after running the script is complete to have the classpath appended, this is less simple...
with the same script example above (saved as eg.sh)

if you ran
./eg.sh
echo classpath is $CLASSPATH

afterwards the CLASSPATH env var. is the same as before (since the environment is only set in current shell, and script runs as its own shell).

instead, "source" the script, rather than running it:

. ./eg.sh

This will execute the "export" in the same shell as it is sourced, hence changing it in the current env.

Hope this helps.
C.
0
 

Author Comment

by:ICPooreman
ID: 17860090
The first part changes the variable in my script but my commands in the script later are still using the original set in the .bashrc file.  If I do an echo on CLASSPATH the value will have changed however, it doesn't appear to be effecting the later commands in the script.

I'm unfamiliar with what the second option is supposed to be doing but it didn't work either.  It closed down my shell and nothing happened when I ran it.
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 17860126
Do you have the "export" in place? without the "export" settings to the variable are only for the shell itself, not children - the export makes the change for the current shell's children processes (i.e. the "java" command).

The second approach would exit the command shell if there's an exit...

you can also specify classpath variables for Java, e.g.

#!/bin/bash

export MY_CLASSPATH=$CLASSPATH:my.jar

java -cp $MY_CLASSPATH my.org.HelloWorld

Cheers,
C.

0
 

Author Comment

by:ICPooreman
ID: 17860534
You're right it was a typo on my side, Sorry thanks for the help
0
 
LVL 11

Expert Comment

by:cjjclifford
ID: 17860564
Glad to be of help!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 121
Separate into files by filename 12 82
deburging in oracle form 12 99
twoTwo  challenge 35 102
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question