LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-14-2005, 12:05 PM   #1
suneel
LQ Newbie
 
Registered: Nov 2005
Location: Hyderabad
Distribution: Fedora
Posts: 5

Rep: Reputation: 0
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?)
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 11-14-2005, 01:49 PM   #2
bosewicht
Senior Member
 
Registered: Aug 2003
Location: Houston, TX
Distribution: Arch
Posts: 1,381

Rep: Reputation: 47
env --unset=helo world

To remove variable helo world.

 
1 members found this post helpful.
Old 11-14-2005, 09:06 PM   #3
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 53
unset temp
 
3 members found this post helpful.
Old 11-15-2005, 12:14 PM   #4
suneel
LQ Newbie
 
Registered: Nov 2005
Location: Hyderabad
Distribution: Fedora
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 11-30-2005, 12:22 PM   #5
shevegen
Member
 
Registered: May 2004
Distribution: Slackware / GoboLinux / LFS / VoidLinux
Posts: 145

Rep: Reputation: 26
How do I delete all Variables?
 
Old 11-30-2005, 08:21 PM   #6
arrenlex
Member
 
Registered: Jul 2005
Distribution: Debian Etch
Posts: 48

Rep: Reputation: 17
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.
 
2 members found this post helpful.
Old 03-09-2009, 11:30 AM   #7
sharky
Member
 
Registered: Oct 2002
Posts: 569

Rep: Reputation: 84
Quote:
Originally Posted by arrenlex View Post
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.
 
Old 09-14-2009, 10:17 AM   #8
linuxLuser
Member
 
Registered: Jan 2005
Distribution: Gentoo
Posts: 111

Rep: Reputation: 16
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.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to export environment variable from a bash script dimaash Linux - Newbie 20 08-09-2011 07:12 AM
environment variable gamor Linux - Newbie 4 04-30-2005 05:28 PM
BASH variables getting unset outside of loop trevelluk Programming 2 03-25-2005 07:14 AM
unset a readonly variable hamster Linux - General 2 05-19-2003 05:13 PM
environment variable mimi Linux - General 2 04-10-2002 07:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration