diff options
-rwxr-xr-x | tests/env.test | 5 | ||||
-rw-r--r-- | toys/posix/env.c | 6 |
2 files changed, 10 insertions, 1 deletions
diff --git a/tests/env.test b/tests/env.test index 4df118dd..63b9094d 100755 --- a/tests/env.test +++ b/tests/env.test @@ -21,3 +21,8 @@ testcmd "early fail" '--oops 2> /dev/null ; echo $?' "125\n" "" "" testcmd "why is this allowed" "=BLAH env | grep '^=BLAH\$'" "=BLAH\n" "" "" testcmd "replace" "A=foo PATH= `which printenv` A" "foo\n" "" "" + +# env bypasses shell builtins +ln -s "$(which echo)" true +testcmd "norecurse" 'env PATH="$PWD:$PATH" true hello' "hello\n" "" "" +rm true diff --git a/toys/posix/env.c b/toys/posix/env.c index 01aa5ec4..19cd18a0 100644 --- a/toys/posix/env.c +++ b/toys/posix/env.c @@ -44,7 +44,11 @@ void env_main(void) for (; *ev; ev++) if (strchr(*ev, '=')) xsetenv(xstrdup(*ev), 0); - else toys.stacktop = 0, xexec(ev); + else { + // a common use of env is to bypass shell builtins + toys.stacktop = 0; + xexec(ev); + } for (ev = environ; *ev; ev++) xprintf("%s%c", *ev, '\n'*!FLAG(0)); } |