Solved

edit CLASSPATH in .bashrc from schell script

Posted on 2006-11-02
5
1,050 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

626 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