aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2019-07-06 15:54:56 -0500
committerRob Landley <rob@landley.net>2019-07-06 15:54:56 -0500
commit6a63b625bfa2c0e86c18ccb5bdc71010e24c9829 (patch)
tree34e31ceefcf14059ef01131e9180912185a75905
parent5822475e0d0be7825406c4f4197375a532fc831f (diff)
downloadtoybox-6a63b625bfa2c0e86c18ccb5bdc71010e24c9829.tar.gz
Add comment and test.
-rwxr-xr-xtests/env.test5
-rw-r--r--toys/posix/env.c6
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));
}