Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Environment Variables...

  1. #1

    Default Environment Variables...

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

    Code:
    NAME=VALUE
    <- So I do "BLAH=/" then it says to see the variable type
    Code:
    '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?

    Thanks!

  2. #2

    Default Re: Environment Variables...

    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'?

  3. #3
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Environment Variables...

    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?

  4. #4

    Default Re: Environment Variables...

    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.

  5. #5
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Environment Variables...

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

  6. #6
    bmynars NNTP User

    Default Re: Environment Variables...

    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.

  7. #7
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Environment Variables...

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

  8. #8

    Default Re: Environment Variables...

    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.

  9. #9
    Join Date
    Jan 2008
    Location
    N40 44.977 W073 59.356
    Posts
    1,170

    Default Re: Environment Variables...

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

  10. #10
    Join Date
    Jan 2008
    Location
    N40 44.977 W073 59.356
    Posts
    1,170

    Default Re: Environment Variables...

    Quote Originally Posted by trizicus View Post
    I'm taking a class right now for my Linux+ and I'm doing exactly what it says for setting environment variables.

    Code:
    NAME=VALUE
    <- So I do "BLAH=/" then it says to see the variable type
    Code:
    '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?

    Thanks!
    Move complete.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •