Sponsored Content
Top Forums Shell Programming and Scripting How to unset all variables in shell? Post 302358062 by aigles on Thursday 1st of October 2009 09:13:31 AM
Old 10-01-2009
The following function 'gsunset', deletes the variables specified by an RE :
Code:
gunset()
{
  local var_re="${1:-.*}"
  eval $( set | \
         awk -v FS='='        \
             -v VAR="$var_re" \
            '$1 ~ VAR { print "unset", $1 }' )
}

VAR1=value1
VAR2=value2
VAR3=value3

echo "Vars before gunset"
set | grep ^VAR
gunset 'VAR.*'
echo "Vars after gunset"
set | grep ^VAR

Output
Code:
Vars before gunset
VAR1=value1
VAR2=value2
VAR3=value3
Vars after gunset

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to unset 'finger' info?

Hi, Command "chfn" can be used to change finger information.. can anybody tell me how to unset i mean reset the same finger information. Thanks in advance, Chanakya (3 Replies)
Discussion started by: Chanakya.m
3 Replies

2. UNIX for Advanced & Expert Users

how to unset the readonly variable

Hi All, May be this is a very simple question... $ b=8 $ readonly b $ echo $b 8 $ b=90 -bash: b: readonly variable $ unset b -bash: unset: b: cannot unset: readonly variable I m not able to change the readonly mode of variable b Please help me out.. Thanks Nidhi (2 Replies)
Discussion started by: Nidhi2177
2 Replies

3. Shell Programming and Scripting

How to check exit status of unset variables

Hi All, Is there any way to check exit status of unset variables? In the following code PathX is not set and the script terminates without checking exit status. #!/bin/bash Path="/tmp/log" cd ${PathX:?} if ;then echo "Exit Status : non zero" else echo "Exit Status :... (2 Replies)
Discussion started by: sussus2326
2 Replies

4. UNIX for Advanced & Expert Users

unset .bashrc

Could someone please tell me how to unset your .bashrc? I have tried all of these. I can't find anything useful from google. unset -f .bashrc unset .bashrc (9 Replies)
Discussion started by: cokedude
9 Replies

5. Shell Programming and Scripting

[ask] about unset variables

I'm wondering, is the number of variables will affect execution time of my bash script or maybe affect the cpu workload, cpu memory, etc ? If I create so many variables, should I unset each one of that variables after I used them or after I think they are no longer needed? and if my script... (2 Replies)
Discussion started by: 14th
2 Replies

6. Shell Programming and Scripting

Unset variables in shell when it running two different loops

I have a script to start/stop/restart the tomcat application. When we run the script first time i.e stop/start it set all env variables(DISTRIB_ID,NAME,TOMCAT_CFG,....etc),but when we restart the tomcat it is running in the same shell.....I need to set the variables when i restart the tomcat(in the... (1 Reply)
Discussion started by: praveen265
1 Replies

7. Shell Programming and Scripting

Unset variable with characters in value

I have a script with a $PASSWORD variable. I unset it right after using it, just to minimize the chance it could be left around for a snooper. That worked just fine... until I used a password with a value of "P@ssw0rd" Now, unset (even with -f, even with the variable enquoted) tells me: unset:... (1 Reply)
Discussion started by: jnojr
1 Replies

8. Shell Programming and Scripting

Listing all local variables for unset

I have tried to thoroughly search other threads before posting this question... I have a shell script (bsh) that I'd like to "re-execute" if the user chooses to. Before the program is executed again the local variables (those set within the script) need to be unset. Is there a command that... (6 Replies)
Discussion started by: powwm
6 Replies

9. UNIX for Dummies Questions & Answers

Unset environement variable

Hi, I have the following line in the script unset _SET_ENV_AA unset _SETENV but where I can check the value for this environement variable (2 Replies)
Discussion started by: stew
2 Replies

10. UNIX for Dummies Questions & Answers

Where unset command locates?

Hi, Can someone tell what is the path for "unset", I tried "which" command but getting below error # which unset /usr/bin/which: no unset in (/usr/lib/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin/:/root/bin) (9 Replies)
Discussion started by: stew
9 Replies
unset(n)						       Tcl Built-In Commands							  unset(n)

__________________________________________________________________________________________________________________________________________________

NAME
unset - Delete variables SYNOPSIS
unset ?-nocomplain? ?--? ?name name name ...? _________________________________________________________________ DESCRIPTION
This command removes one or more variables. Each name is a variable name, specified in any of the ways acceptable to the set command. If a name refers to an element of an array then that element is removed without affecting the rest of the array. If a name consists of an array name with no parenthesized index, then the entire array is deleted. The unset command returns an empty string as result. If -nocom- plain is specified as the first argument, any possible errors are suppressed. The option may not be abbreviated, in order to disambiguate it from possible variable names. The option -- indicates the end of the options, and should be used if you wish to remove a variable with the same name as any of the options. If an error occurs, any variables after the named one causing the error are not deleted. An error can occur when the named variable does not exist, or the name refers to an array element but the variable is a scalar, or the name refers to a variable in a non-existent namespace. EXAMPLE
Create an array containing a mapping from some numbers to their squares and remove the array elements for non-prime numbers: array set squares { 1 1 6 36 2 4 7 49 3 9 8 64 4 16 9 81 5 25 10 100 } puts "The squares are:" parray squares unset squares(1) squares(4) squares(6) unset squares(8) squares(9) squares(10) puts "The prime squares are:" parray squares SEE ALSO
set(n), trace(n), upvar(n) KEYWORDS
remove, variable Tcl 8.4 unset(n)
All times are GMT -4. The time now is 12:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy