Welcome, Guest. Please login or register.

Author Topic: Linux Question  (Read 1720 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline tonywTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 553
    • Show only replies by tonyw
Linux Question
« 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
 

Offline KennyR

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 8081
    • Show only replies by KennyR
    • http://wrongpla.net
Re: Linux Question
« Reply #1 on: February 17, 2003, 09:43:12 AM »
The *ix filing system...the horror...

But seriously, how do you think Slashdot got its name? ;-)
 

Offline DaveP

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2116
    • Show only replies by DaveP
Re: Linux Question
« Reply #2 on: February 17, 2003, 10:28:03 AM »
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
$

Hate figure. :lol:
 

Offline tonywTopic starter

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 553
    • Show only replies by tonyw
Re: Linux Question
« Reply #3 on: February 18, 2003, 05:01:53 AM »
Thanks, Dave. That's the sort of answer I needed.

Grrrr - Linux command names - what sort of name is "." ??

tony
 

Offline dezignersrepublic

  • Sr. Member
  • ****
  • Join Date: Sep 2002
  • Posts: 370
    • Show only replies by dezignersrepublic
    • http://www.findingthem.com
Re: Linux Question
« Reply #4 on: February 18, 2003, 05:41:50 PM »
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.

--
 

  • Guest
Re: Linux Question
« Reply #5 on: February 18, 2003, 06:06:39 PM »
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