unless you're using a _lot_ of env vars, or are in an environment with
very limited memory, i wouldn't worry about unsetting variables unless you
really don't want those vars to exist for logic later in the script. when
the shell process terminates, any memory the env vars were using would be
freed along with it.
unless maybe you're spawning a bunch of children off from the script and
don't want the env vars passed to them, but otherwise yeah, the env vars
won't get passed up to the parent, and therefore won't use any resources
after the shell exits.
i don't see many scripts that ever bother unsetting env vars in general.
-tcl.
On Fri, 26 Jan 2001, Brad Doster wrote:
> When is it necessary/desireable (probably 2 different questions) to unset
> variables created within a script? I've written a bash function that gleans
> most, if not all, variables created within a script, then unsets them. But,
> when it runs, it takes a second or two, which isn't bad, but feels like
> forever when waiting for the bash prompt to reappear. So now I'm wondering
> if it's worthwhile or even needed.
>
> I understand that the script variables cannot be exported to the parent
> shell, so I guess the question is... if not unset, do script variables still
> consume system resources once a script terminates and returns to the shell?
>
> In case it is worthwhile, the function is listed here for those that might
> benefit from it. If it's not worthwhile, well, writing it has been a good
> learning experience -- those that read and helped with my removing '$'s and
> concatenating variables with <newline> questions will recognize some of the
> code.
>
> Thanks!
>
> bd
>
>
> # Cleanup - unset all variables; if desired, show a closing message, then
> exit
> cleanup() {
>
> # Arguments: "custom message"
>
> # Get all variable names created with 'varname='
> varlist=`cat $0 | grep = | awk '{ print $1 }' | grep = | \
> awk -F "=" '{ print $1 }'`
>
> # Get variables created with 'for', 'read', ,select', etc.
> for varname in case for read select until while ; do
> # There's a <space><tab> inside the grep'd []s
> morevars=`cat "$0" | grep "^[ ]*$varname " | sed 's/ \[ //
> s/"//g ; s/\\$//g' | awk '{print $2}'`
> varlist=`echo -e "$varlist\n$morevars"`
> done
>
> varlist=`echo "$varlist" | sort | uniq`
>
> for vname in $varlist; do
> unset $vname
> done
> unset vname
>
> if [ -n "$1" ]; then
> clear
> echo "$1"
> echo
> fi
> exit
> }
>
>
>
>
> _______________________________________________
> Redhat-list mailing list
> [EMAIL PROTECTED]
> https://listman.redhat.com/mailman/listinfo/redhat-list
>
_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list