LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-24-2009, 05:45 PM   #1
linux_user_123
LQ Newbie
 
Registered: Oct 2008
Posts: 8

Rep: Reputation: 0
Can a bash function unset itself?


I have many bash functions, like the example below, where the bash function unsets itself when it is done. Its has always (and still does) work. However, recently I was asked to find documentation showing this is a supported use case.

Can someone point me to a reference?

Primary environment is Debian Etch/Lenny with bash 3.x.

bash% ( set -x ; function a { echo aa ; unset a ; } ; set | grep ^a ; a ; set | grep ^a ; a )
+ set
+ grep '^a'
a ()
+ a
+ echo aa
aa
+ unset a
+ set
+ grep '^a'
+ a
bash: a: command not found
 
Old 07-24-2009, 10:23 PM   #2
penguiniator
Member
 
Registered: Feb 2004
Location: Olympia, WA
Distribution: SolydK
Posts: 442
Blog Entries: 3

Rep: Reputation: 60
Hmm... from the bash 'help unset' command:

unset: unset [-f] [-v] [name ...]
For each NAME, remove the corresponding variable or function. Given
the `-v', unset will only act on variables. Given the `-f' flag,
unset will only act on functions. With neither flag, unset first
tries to unset a variable, and if that fails, then tries to unset a
function.

Nothing here explicitly forbids unsetting a function from within the function, and it does work. Kind of like the tapes Mr. Phelps listened to at the beginning of each episode of Mission Impossible: "Good Morning, Mr. Phelps... This tape will self-destruct in 10 seconds...."
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to unset environment variable in bash suneel Linux - Newbie 7 09-14-2009 10:17 AM
Bash looping or function within a function FirmbIT Programming 2 04-24-2006 01:06 PM
BASH variables getting unset outside of loop trevelluk Programming 2 03-25-2005 07:14 AM
Bash function pazvant Linux - Software 1 03-08-2005 07:47 AM
compile within bash function? adam_boz Programming 1 09-17-2002 11:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:26 PM.

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