Amiga.org
Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: tonyw on February 17, 2003, 01:50:25 AM
-
I'm using the kaffe JVM under ixemul, getting it to run under AmigaOS. I have to type in long class path strings every time I open a new shell and it's boring.
How can I do this in a Linus script file? The commands I want to execute are:
export PATH=
export CLASSPATH=
export KAFFELIBRARYPATH=
I put these commands in a script "help" but /bin/sh won't recognise them and gives the error "./help: no such file or directory". If I leave out the "./" I get "help: not found".
I think that the shell isn't even reading the script, which has props of rwxr-xr-x (755).
Any help appreciated.
tony
edit:
Thanks anyway, but I got the answer: use the ".", as in ". ./file"
[Had to ask my daughter - cringe]
tony
-
The *ix filing system...the horror...
But seriously, how do you think Slashdot got its name? ;-)
-
You have two problems. Firstly the current directory (relative to
wherever you are ) is not in your path.
export PATH=$PATH:.
'.' is your current directory. You might want to add that line
to your .bashrc file so '.' is always in your path.
The second problem you have is that if you do not "source" the
script the exported variables will have no effect.
By default Unix based shells spawn a new process in
order to run your script copying the current environment
into the child.
That means that you run 'help' from process 1 by typing
in 'help' at the shell, Linux creates a new child process of process
1 - lets call it process 2, to run the script. The script sets
PATH, CLASSPATH etc in process 2. The script ends. Process
2 is deleted and you are back in process 1 ( which has
not been modified by the script because that is not where
it ran ).
To run a script in the current process you need to use
the '.' command. This ensures that whatever script you run
runs in this process - process 1. That means that the
variables you export are exported in process 1.
sooo
$ export CLASSPATH=cun/i/lingus
$ help
Spawns process 2 ( new process )
runs help in process 2
Process 2 dies
$ echo $CLASSPATH
cun/i/lingus
$
$ export CLASSPATH=cun/i/lingus
$ . help
runs help in process 1 ( this process )
$ echo $CLASSPATH
cun/i/lingus
$
-
Thanks, Dave. That's the sort of answer I needed.
Grrrr - Linux command names - what sort of name is "." ??
tony
-
I would suggest adding the path vars to your .bash_profile file (assuming you use bash).
Otherwise make sure your script has
#!/bin/sh
at the top of the script.
-
I don't remember the reasoning, but I remember it made
sense to me at the time...
It is considered a Unix no-no to put '.' into the path.
I would just make sure the file starts with #!/bin/sh, and run it using ./script.sh (assuming the file name is script.sh).
Andrew