NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Silly shell question



It's simpler than that. KSH (along with SH, BASH and similar shells) have two sets of variables. Local and environment. A variable can only exist in one of these. By default, when a variable is created, it is local. If you export it, it becomes an environment variable.

Only environment variables are propagated to child processes.

(In shells from the csh family, you have different commands for dealing with local and environment variables, so there it is a bit more obvious what you are doing.)

	Johnny

On 2016-03-22 21:39, Swift Griggs wrote:

In ksh, when you use the 'export' keyword, what is actually going on?
Does it create a copy of the variable in memory? I doubt it since I
tried a test and I could see the exported version changing even if I
just change the original variable:

# FOO=abc
# export FOO
# ksh
# echo $FOO
abc
# exit
# FOO=123
# ksh
# echo $FOO
123
# exit

So, what is that really happens with exported variables? Does the
shell/app that's starting up check for exported variables and somehow
import them? How can it tell? I noticed there are a LOT of checks around
exported variables in ast-ksh. It appears to be a dangerous proposition
in some cases.

Sorry if this seems like a dumb question. I'm just curious about the
intrinsics of how it works. I looked at the source code for ast-ksh, but
it's pretty huge and hard to follow to answer this question. I'm just
wondering what the key mechanism is. Curiosity only.

-Swift


--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index