LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to unset environment variable in bash (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-unset-environment-variable-in-bash-383066/)

suneel 11-14-2005 12:05 PM

how to unset environment variable in bash
 
Hi,
I am using bash(Fedora 3). I have set an enviroment variable using:
export temp='Helo world'
How do I remove temp from enviroment?
I guess this can be done in csh using unsetenv.
One more question: Whats the difference between the output of a set and export with out options. (Both of them print all the environment variables. export just prints all the variables prefixed with 'declare -x'. What is it meant for?)

bosewicht 11-14-2005 01:49 PM

env --unset=helo world

To remove variable helo world.

:)

foo_bar_foo 11-14-2005 09:06 PM

unset temp

suneel 11-15-2005 12:14 PM

Hi bosewicht,
I tried your suggestion ie env --unset=temp. But it just printed all the environment variables without unsetting temp.

Hi foo_bar_foo,
thanks for the reply. It works

shevegen 11-30-2005 12:22 PM

How do I delete all Variables?

arrenlex 11-30-2005 08:21 PM

You really don't want to. If you unset your PATH, for example, you won't be able to run any applications and you might have a ton of trouble putting it back.

I suggest running the 'env' command to list all variables defined on your system and unset only the ones you know you don't need or want.

With Linux, it's generally a very bad idea to delete something when you don't know what it is\does.

sharky 03-09-2009 11:30 AM

Quote:

Originally Posted by arrenlex (Post 1977465)
You really don't want to. If you unset your PATH, for example, you won't be able to run any applications and you might have a ton of trouble putting it back.

I suggest running the 'env' command to list all variables defined on your system and unset only the ones you know you don't need or want.

With Linux, it's generally a very bad idea to delete something when you don't know what it is\does.

Sometimes I do want to unset everything. I build startup scripts for endusers running ic design tools. To try and have all tools run in identical environments start all my scripts with the following:

Code:

#!/bin/tcsh -f

# get USER, HOME and DISPLAY and then completely clear environment
set U = $USER
set H = $HOME
set D = $DISPLAY
unsetenv *

# set USER, HOME and DISPLAY and set minimal path.
setenv USER $U
setenv HOME $H
setenv DISPLAY $D

# initial path
set path = (/bin /usr/bin /usr/local/bin /usr/bin/X11 /usr/contrib/bin \
/usr/contrib/bin/X11)

I grab USER, HOME and DISPLAY and flush the rest. I then set a minimal path. I would like to know how to do something similar in bash.

linuxLuser 09-14-2009 10:17 AM

Unset ALL environment variables in BASH (not a good idea!):

Code:

$ unset `env | awk -F= '/^\w/ {print $1}' | xargs`
$ env
bash: env: No such file or directory
$ ls
bash: ls: No such file or directory

Enjoy. :)


All times are GMT -5. The time now is 02:39 AM.