On Sat, Aug 17, 2002 at 03:06:16PM +0200, Alain Barthélemy wrote:
- now - if I type in console mode: - LASTFILE=whatever - export LASTFILE
and run my script with the line:
echo "$LASTLINE"
I read: whatever
Thus, the variable is well exported when I type the instruction in console mode (thus in a xterm of course) but not when the same lines are executed via a bash script
Now if I leave the X environment (out blackbox thus)and type, on console mode:
echo "$LASTLINE"
====> nothing, nothing, nothing
Thus a global variable in a xterm console is not the same global variable in console mode with the same user.
Thus how to uniformize all these environments and have them talk the same language.
export does not create a "global variable" that persists from one process to another. What it does do is cause sub-processes to get a copy of the original process's variable. Any changes made to that copy by the sub-process do not affect the original copy held by the original process. (And therefore do not get passed on to other sub-processes started by the original process at some later time.) Perhaps you could put the value into a file: #!/bin/bash # script1 myvar="Hello World!" echo $myvar > some_file #!/bin/bash # script2 myvar=$(cat some_file) echo $myvar Test this by running script1 followed by script2: ./script1 ./script2 Hello World! Another possibility is to "source" your scripts. This causes them to as part of the original process so that they share variables: #script3 myvar="Hello Sailor!" #script4 echo $myvar Test this as follows: source script3 source script4 Hello Sailor! As a shortcut, "source" can be replaced by a single dot: . script3 . script4 Hello Sailor! -- Robert C. Paulsen, Jr. robert@paulsenonline.net