Welcome, Guest. Please login or register.

Author Topic: Linux Question  (Read 1732 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline DaveP

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2116
    • Show all replies
Re: Linux Question
« 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: