Linux Set v/s Env | Shell v/s Environment Variables - BASH only

harmandeep

VirTuaLiZaTioN Freak
Disciple
Hi, linux newbie here !

I )
Stuck with difference b/w Local Shell variables and Environment variables with respect to BASH only !

Refer here Variables: to section 3.2.1.2. Local variables

II ) CORRECT me if i m wrong : In BASH , Environment Variables = Exported Variables. & and ENVIRONMENT Variables can be viewed with ENV or PRINTENV.

They had compared output of Set and Env comparing the VARIABLES listed.

Now are these Listed variables really Local Variables,and if yes, howcome PS1,PS2 ... which are listed under SET command output, are inherited by BASH Subshells or even new BASH Tabs , whereas in BASH , only exported variables are passed to Child Processes / Subshells.( which we open via gnome-terminal ) ( again Correct ME :S )

and if these variables ( PS1 ) Gotta do with Fork and EXEC procedure, i.e they are being passed to Child Process/SubShell via Fork and Exec,can they be demonstrated....

I tried to do the same , do know the procedure was correct or not.

0)using RHEL 5 | NON interactive Shell ( bash )

1) open bash terminal

2) #monitor=lg

3) #echo $monitor ( value displayed )

4) #exec bash

5) #echo $monitor ( value not displayed )

III ) With Respect to BASH , are Global Variables same as Environment Variables or not.

Note : As per set info page, it displays Local and Environment Variables , Functions , and Shell Parameter Features.

:ashamed:
 
Not pretending to be a bash expert but here's my understanding. Folks please correct me if I messed up somewhere.

When you invoke bash using a login shell (RHEL5 GDM in your case), bash first tries to read what's in /etc/profile. That file will contain global settings. It then tries to read what's in your ~/.bash_profile. Those are your 'local settings' (tied to your login alone). There are a couple of other files that bash then tries to look for. ~/.bash_login and ~.profile perhaps? Not sure about that part.

When an interactive shell is started (non-login) and you are running bash (new tab in gnome terminal say), bash looks for /etc/bash.bashrc (not 100 %s sure about this one). That will again contain global settings. It then looks for your ~/.bashrc which will contain settings tied to your login.

Typically you'd modify PATH using ~/.bash_profile and put other environmental variables there (installation dir for apps for example). You'd put aliases in ~/.bashrc.

I suspect that if you change #2 to 'export monitor=lg', #5 will indeed display a value.
 
you need to change step 4 ... use this

Code:
exec bash --noprofile

if this doesn't work then also try these

Code:
exec bash --norc

Code:
exec bash --noprofile --norc
 
@ Palemantle --- look for Info pages to be exact regarding BASH Startup Procedure ( Initialization ) ... read the first main post , to be sure , of what am i asking ...

@ kekerode --- i am not concerned with Bash Initialization , but how does it differs Exported v/s Non Exported Variables --- With respect to the provided link in II )

Still looking for answer
 
Back
Top