PDA

Bekijk de volledige versie : System wide variable (how to?)



scriptman
24-11-2006, 10:13
Can anyone tell me how to make a system wide variable stick across different scripts? Kind of like SETX does in dos.?

I tried using 'export test='helloworld' but it only stick for the script thats running it?

thanks,

Scriptman

oleo
24-11-2006, 13:29
yust interpret the script with a dot and not run them.

Instead of
./foo.sh execute
. ./foo.sh

scriptman
25-11-2006, 11:16
yust interpret the script with a dot and not run them.

Instead of
./foo.sh execute
. ./foo.sh

Hi Oleo,
I'm not sure what you mean, please note my Linux is very limited , you may have already told me but I don’t understand?:o

I'm trying to run a script that sets a variable “something=hello” and when the script ends I would like that variable to be a system wide variable that is if I type "set" at the command prompt I should be able to see something=’hello’ then I would like to use that variable in another script eg. “Echo $something” result should be “hello”.

Hope that helps?

SM

vlx
26-11-2006, 19:24
Hi Oleo,
I'm not sure what you mean, please note my Linux is very limited , you may have already told me but I don’t understand?:o

I'm trying to run a script that sets a variable “something=hello” and when the script ends I would like that variable to be a system wide variable that is if I type "set" at the command prompt I should be able to see something=’hello’ then I would like to use that variable in another script eg. “Echo $something” result should be “hello”.

Hope that helps?

SM

Hi, There is no easy way to do it that way you describe. In unix every process has its own variables.
So Oleo is suggesting you just to source the script inside not to run it alone:

. ./foo.sh is something like include.

It will execute the commands in ./foo.sh but in the context of running script.
If you want it truly the way you describe, you must share the variable in some form between processes, for examle in textfile or you can use nvram [but do not use commit].

Texfile version: create some textfile [say ./indude.txt] and write variables to that file from script:
VARIABLE1=3232
..some code..
echo "VARIABLE1=$VARIABLE1" >./include.txt
and then source the file in other script:
. ./include.txt

Nvram version:

to set:
variable1=23232
... some code...
nvram set "variable1=$variable1"
to get:
variable1=$(nvram get variable1)

Take this just as examples how to do it. There are other ways [harder od simpler]

scriptman
27-11-2006, 00:00
Hi, There is no easy way to do it that way you describe. In unix every process has its own variables.
So Oleo is suggesting you just to source the script inside not to run it alone:

. ./foo.sh is something like include.

It will execute the commands in ./foo.sh but in the context of running script.
If you want it truly the way you describe, you must share the variable in some form between processes, for examle in textfile or you can use nvram [but do not use commit].

Texfile version: create some textfile [say ./indude.txt] and write variables to that file from script:
VARIABLE1=3232
..some code..
echo "VARIABLE1=$VARIABLE1" >./include.txt
and then source the file in other script:
. ./include.txt

Nvram version:

to set:
variable1=23232
... some code...
nvram set "variable1=$variable1"
to get:
variable1=$(nvram get variable1)

Take this just as examples how to do it. There are other ways [harder od simpler]


Thanks VLX!!

I like the nvram method :)

I'll use that, thankyou again!!

sm