On Thu, 2009-11-12 at 15:54 +0100, Bernhard Reutner-Fischer wrote:
> On Thu, Nov 12, 2009 at 03:09:12PM +0100, Bernd Petrovitsch wrote:
> >On Thu, 2009-11-12 at 16:57 +0300, Vladimir Dronnikov wrote:
> >> >
> >> > Using export -n or unset?
> >> >
> >>
> >> I need command to effectively perform clearenv(), to unset all vars at
> >> once ( that's why I tried "env -" :). Is there such in the nature?
> >No, no one really wants to delete/unexport *all* environment variables
> >as that includes $HOME and $PATH (to name 2 that come immediately to my
> >mind).
> >FWIW
> >---- snip ----
> >unset $(env | sed -e 's/=.*//')
> >---- snip ----
> >does the trick (in a bash). Similar should be doable for other shells.
>
> env | cut -d'=' -f1 | while read i;do unset $i;done
In my world, the "cut" and "while" are in sub-processes of the original
shell (which is the reason for the "$(..)" construct. Backquote should
do the trick too BTW). So more like
---- snip ----
for v in `export | while read i; do IFS="= " set -- $i; echo "$1"; done`; do
unset "$v"; done
---- snip ----
if one doesn't want to use `sed` (or `cut` or some other external
program) and work with old shells (and e.a. busybox `sh`, `ash` and
`msh`. Doesn't do in `hush` though).
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox