Click to See Complete Forum and Search --> : question about a bash script


cotfessi
08-06-2003, 05:08 PM
I'm trying to have a simple script to change to a different directory... can I do this? :confused:

here is the very simple script:

# Change the directory
cd /opt/WebSphere/AppServer/installedApps/linuxp1/someEAR.ear/


Here is evidence that the directory does indeed exist:


[root@linuxp1 linuxp1]# pwd
/opt/WebSphere/AppServer/installedApps/linuxp1

[root@linuxp1 linuxp1]# ls -l
total 12
drwxr-xr-x 4 root root 4096 Jun 17 10:24 adminconsole.ear/
drwxr-xr-x 14 root root 4096 Jun 17 09:34 MDBSamples.ear/
drwxr-xr-x 11 root root 4096 Aug 6 10:55 someEAR.ear/

[root@linuxp1 linuxp1]#

Stuka
08-06-2003, 05:10 PM
The typical problem with the cd script is that the script is launched in a copy of the shell, NOT the actual shell you launch it from. You might want to try an alias instead.

cotfessi
08-06-2003, 06:19 PM
my example script above was a stripped down version of what I actually wanted to do... I wanted to change to a number of different directories and add any jar files to the CLASSPATH variable...

is there a way to accomplish this?

chrism01
08-07-2003, 08:04 AM
use the syntax:
. yourscript

thats a dot followed by a space. That runs the script in the CURRENT shell, so changes to env vars should remain on completion.

bwkaz
08-07-2003, 07:52 PM
Something like:

dirlist="/path/to/dir1 /path/to/dir2 /path/to/dir3"

for dir in $dirlist ; do
cd $dir
for file in *.jar ; do
CLASSPATH=$CLASSPATH:$dir/$file
done
done You NEED to source this file (using .), as was mentioned previously. Otherwise the changes to the CLASSPATH variable won't take effect.