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’?
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:
A=B
‘env’ A doesn’t show up
‘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.
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
LOGNAME=$(whoami)
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.
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:
1)
A) A=B
B) ‘env’
2)
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.
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
'env'
when you should type
env
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.
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.