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 |
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...." |
All times are GMT -5. The time now is 03:42 AM. |