[Gllug] ADVERT: Shell Scripting book

Steve Parker steve at steve-parker.org
Wed Jul 20 20:58:49 UTC 2011


On 20/07/11 21:50, Alain Williams wrote:
> On Wed, Jul 20, 2011 at 09:40:17PM +0100, Steve Parker wrote:
>    
>> On 20/07/11 21:33, Nix wrote:
>>      
>>> On 20 Jul 2011, Steve Parker outgrape:
>>>
>>>
>>>        
>>>> All shell variables are environment variables;
>>>>
>>>>          
>>> Certainly not. All environment variables are shell variables, though.
>>>
>>>        
>> You may not be interactively using the environment, but the two things
>> are the same,
>>      
> Try the following:
>
> 	foo=bar
> 	echo $foo
> 	env|grep foo
> 	export foo
> 	env|grep foo
>
>    
Here $foo has not been exported to env, but $foo is still a variable in 
your current running shell.
env is not a shell builtin; it does not report on your shell's state, 
but on what your shell exports to called programs.
Granted, we're getting down to terminology here, but from the bash man 
page (with my emphasis added):

       When a simple command other than a builtin or shell function is 
to be executed, it is invoked
        in  a *separate execution environment* that consists of the 
following.  Unless otherwise noted,
        the values are inherited from the shell.
        *     the shell's open files, plus any modifications and 
additions specified by redirections
               to the command
        *      the current working directory
        *     the file creation mode mask
        *      shell variables and functions *marked for export*, along 
with variables exported for the
               command, passed in the environment

The shell's environment (realistically in this context, a shell script's 
environment) contains all of its variables (including an unexported 
$foo). External commands are run in their own environment; not all of 
your environment is exported to commands that you call, but all of your 
variables are part of your environment.

That is all that I was saying; exporting and scope are of course a topic 
in their own right, which are covered in Chapter 7 of the book, 
including the above.

Steve
--
Gllug mailing list  -  Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug




More information about the GLLUG mailing list