"env -" segfaults
Ralf Friedl
Ralf.Friedl at online.de
Thu Nov 12 15:23:48 UTC 2009
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:
>>
>>> 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?
>>>
>> ---- 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
>
Actually:
$ env | cut -d'=' -f1 | while read i;do unset $i;done; env
PATH=...
HOME=...
The reason is that the shell has to fork to attach the pipe to the while
loop, so the changes only affect the forked process, not the original
shell. So it is necessary to do the unset in the main shell, while the
generation of the environment names can be done in a subshell. It
doesn't even work with bash, although bash sometimes does tricks with
file descriptors to avoid a fork.
$ unset $(env | cut -d'=' -f1)
--
Ralf Friedl
More information about the busybox
mailing list