OESF Portables Forum
Everything Else => General Support and Discussion => Zaurus General Forums => Archived Forums => Software => Topic started by: gab74 on July 07, 2004, 07:54:37 am
-
I make a simply sh script
test.sh
export PATH=/mnt/card/gcc/bin:$PATH
When i run the script from console as root, the script is executed but PATH still remains unchanged.
if i type the command from console ; it works !!!
Why this ????
I use my SL6000L
Why cannot change PATH with a script....on lInux it works !!!
-
You need to type:
source test.sh
Running a script will simply set the path within the script itself. 'sourcing' a script means all the environment variable changes in the script are applied to the current shell.
-
OK thank you very much for your help ! it works !
-
OK thank you very much for your help ! it works !
actually, you need to understand what is going on....
(and people can correct me, etc).
When you make:
test.sh containt
PATH=${PATH}:/new/path/component
export PATH
and then you run this... your new PATH *is* being set.... in that script... in the "environment" for that
script -- and for the environment in the children of that script... but, when the script ends... that
environment ends.
If you want that command to affect your *current* environment -- you can consider your current
environment the "parent" and that script the "child" ... and you'll probably come across it said that
children can't modify the environment of their parent -- and although this isn't entirely true, it's
mostly good enough for now.
So, in your current environment, you need to update your path.... so, instead of creating a new environment
by running a shell and executing that script, since you're already IN a shell, just load that script into your
current environment --
. /path/to/test.sh
etc.
source is [t]csh .. and I don't know if bash/ksh have it -- the ksh that I am use to does not.
sh has traditionally used "."
You may also see programs that will do things like this (ie: check the start up of any unix/linux box)
#!/bin/sh
. /path/to/ENV
command1
command2
command3
The idea there is that someone puts commands in the "ENV" that make things work -- but then that
environment is needed in many different locations -- and instead of copying it each time (which would work) or calling the script like you did before "/full/path/to/test.sh" (child) which would NOT affect the
current (or parent) environment, the "." is used.
The different is the "relative" environment. Current (parent) or new (child) -- where the child can not
change the parent's env (for the most part, this should be remembered).
most all unix problems/issues come from "path" or "permissions" ... although the example above probably
isn't either, I thought it was woth mentioning (also, it's just my opinion).
Scott