Environment Variables...

I’m taking a class right now for my Linux+ and I’m doing exactly what it says for setting environment variables.


← So I do “BLAH=/” then it says to see the variable type

'set' or 'env'

when I type set I see programming code, when I type ‘env’ I see env variables, but the environment variable is not in there…

Is the Linux+ course I’m taking dated or something?


I changed around the LOGNAME so I noticed that doing ‘LOGNAME=ben’ and the ‘env’ displayed it correctly (I changed it back to original) but then when I try to add a new environment variable, nothing is there…

Hm, then I noticed doing ‘echo $variable’ display the value of the variable but how come it is not displayed in ‘env’?

A=B will appear in set.

A=B; export A (or equivalently in bash: export A=B) will appear in both set and env.

Clear as mud?

Still not showing up in env… And when I use the command, ‘env’ A is not showing up… I’ve tried it in Ubuntu and OpenSUSE…

This is what I do:

  1. A=B
  2. ‘env’ A doesn’t show up
  3. ‘set’ nothing comes up with set at all, I basically get code that is similar to C++ and Java

1A) set A=B
2A) ‘env’ still no A

Does it not appear or something? This is really confusing to be honest…

Like I’ve already stated I can easily change the present variables in the system. Like LOGNAME, when I do LOGNAME=ben it changes. I use ‘env’ and then it shows up changed, but when I add a NEW env variable it’s not present in there.

env only shows environment variables, those that have been exported, as I already explained.

You did not say what shell you are using. Using ‘set’ for setting variables indicates C shell. By default, Linux distributions use BASH as their default preferred shell.

As such, you should do the following in your $HOME/.bashrc

export LOGNAME

or on a single line:

export LOGNAME=$(whoami)

If you have multiple global vars your want to export, do not prefix them with ‘export’. Rather, define them as in my first example and then, do:

export LOGNAME VAR1 VAR2, etc.

Now, re-login or source your .bashrc again (. ./.bashrc) and when you run ‘env’, you will see your GLOBAL vars exported.

However there is a plain set command in bash, which shows the variables in the current shell.

I am using the default shell which is bash. Like I’ve already stated. I’ve tried exporting and the new variable is not created. I’ve tried all other ways and even the way it says in the Linux+ book that I have. Still nothing, and the same was for Ubuntu and in SuSE.

This is what I do I’ve done it many times:
A) A=B
B) ‘env’
A) export A=B
B) ‘env’

Still once again, nothing appears. How am I using a c shell when I use the command ‘echo $0’ it prints out ‘bash’?

I do not have any variables to export… I just want to finish this chapter and as I am moving along I am stuck here. I do not know why… But it’s really annoying.

Moving thread from Install/Boot/Login to Applications forum.

Move complete.

Works fine here, don’t know what you’re missing.

$ export FOO=BAR
$ env | grep FOO

What does running

which env

show? It should be /usr/bin/env

Okay it does show /usr/bin/env… But what you’ve told me to input works…

When I do the ‘env | grep FOO’ it does find the variable that I assigned. But when I do ‘env’ it doesn’t find FOO, is there a reason why to this, or maybe I am just used to the guide I am following?

Maybe it’s there but buried in the long output? Or maybe you typed in


when you should type


It’s just a normal command, you don’t quote it. Maybe the book showed it with quotes?

Another possibility is you tried to change a readonly environment variable. If you use a random name instead of a well-known name you won’t stumble upon a readonly variable.

I’m not that nooby lol… I used the quotes to verify what command I was using; so I was using the command env. I search through all the output and I still do not see FOO lol.

Oh well, maybe you should just move on and consider the lesson learnt. :wink:

I’ll just wait on my college class until I learn linux… lol

This answer may be a bit old, but figured it would help for other puzzled penguins. From my readings a child process cannot alter the environment of the parent process. The way to get around it is to have the parent process execute the commands directly. This is simple just call:

script <file_that_sets_variables>

From my reading, the export keyword tells bash to pass that environment variable to other child processes.

Hope that helps

Take Care

Sorry wrong command, script is not the command, source is.

I meant:

source <file_that_sets_variables>