ksh: 'unset' variables in 'regexp-like' fashion?

ksh: 'unset' variables in 'regexp-like' fashion?

Post by Zdenek Seke » Thu, 03 Jan 2002 22:56:13



The problem is this: a script generates (very) many
variables that have a certain pattern to them, like this:

   $ AB_0_0=1
   $ AB_0_1=2

At some point I need to 'unset' all of them:

   $ unset AB_0_0 AB_0_1

This is practical only for a few of them. Is there a way
to unset all of them in some simple fashion, like

   $ unset AB*  

I know the above (which is meant to be 'regexp-like')
doesn't work, but this is the idea I am after.

If the variables were all exported, one could think of
something like (not pretty):

   $ env | grep '^AB' | while read var
                        do unset ${var%%=*}
                        done

but my variables are not exported (so 'env' doesn't output
them).

Any idea?

---Zdenek

--
=========================================================

VNET: 557-4844                      Silicon Graphics SA
Tel : +41-22-710.4844       18, Ave. Louis Casai, 1209 Geneva
Fax : +41-22-710.4860                   Switzerland

 
 
 

ksh: 'unset' variables in 'regexp-like' fashion?

Post by Bill Marcu » Thu, 03 Jan 2002 23:17:29


Quote:

>If the variables were all exported, one could think of
>something like (not pretty):

>   $ env | grep '^AB' | while read var
>                        do unset ${var%%=*}
> done

>but my variables are not exported (so 'env' doesn't output
>them).

set | grep '^AB' | ...

 
 
 

ksh: 'unset' variables in 'regexp-like' fashion?

Post by Zdenek Seke » Thu, 03 Jan 2002 23:37:39




Quote:

>>If the variables were all exported, one could think of
>>something like (not pretty):

>>   $ env | grep '^AB' | while read var
>>                        do unset ${var%%=*}
>> done

>>but my variables are not exported (so 'env' doesn't output
>>them).

>set | grep '^AB' | ...

Argh, completely overlooked this one...thanks!

---Zdenek

 
 
 

ksh: 'unset' variables in 'regexp-like' fashion?

Post by Brian Hile » Tue, 08 Jan 2002 04:38:35



> ...
> This is practical only for a few of them. Is there a way
> to unset all of them in some simple fashion, like
>    $ unset AB*    
> ...

You are one of the few people I know to be using ksh93, Zdenek; is
this true? If so, you have the capability of doing:

unset ${!AB*}

=Brian

 
 
 

ksh: 'unset' variables in 'regexp-like' fashion?

Post by Zdenek Seke » Tue, 08 Jan 2002 18:17:14





>> ...
>> This is practical only for a few of them. Is there a way
>> to unset all of them in some simple fashion, like
>>    $ unset AB*
>> ...

>You are one of the few people I know to be using ksh93, Zdenek; is
>this true? If so, you have the capability of doing:

>unset ${!AB*}

Hi, Brian, actually both (88/93) but your 93 way above really
intrigued me so I went back to THE book (B&K) and obviously it's all
there, clearly spelled out. Maybe I should read that book more often!
Thanks for putting me on the right track!

---Zdenek