sh: Return 0 from eval if no command was given.
This makes a difference if there is a command substitution. To make this work, evalstring() has been changed to set exitstatus to 0 if no command was executed (the string contained only whitespace). Example: eval $(false); echo $? should print 0.
This commit is contained in:
parent
ec2368eb92
commit
b84d7af7c6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=210829
@ -145,7 +145,8 @@ evalcmd(int argc, char **argv)
|
||||
p = grabstackstr(concat);
|
||||
}
|
||||
evalstring(p, builtin_flags & EV_TESTED);
|
||||
}
|
||||
} else
|
||||
exitstatus = 0;
|
||||
return exitstatus;
|
||||
}
|
||||
|
||||
@ -160,9 +161,11 @@ evalstring(char *s, int flags)
|
||||
union node *n;
|
||||
struct stackmark smark;
|
||||
int flags_exit;
|
||||
int any;
|
||||
|
||||
flags_exit = flags & EV_EXIT;
|
||||
flags &= ~EV_EXIT;
|
||||
any = 0;
|
||||
setstackmark(&smark);
|
||||
setinputstring(s, 1);
|
||||
while ((n = parsecmd(0)) != NEOF) {
|
||||
@ -171,11 +174,14 @@ evalstring(char *s, int flags)
|
||||
evaltree(n, flags | EV_EXIT);
|
||||
else
|
||||
evaltree(n, flags);
|
||||
any = 1;
|
||||
}
|
||||
popstackmark(&smark);
|
||||
}
|
||||
popfile();
|
||||
popstackmark(&smark);
|
||||
if (!any)
|
||||
exitstatus = 0;
|
||||
if (flags_exit)
|
||||
exitshell(exitstatus);
|
||||
}
|
||||
|
4
tools/regression/bin/sh/builtins/eval5.0
Normal file
4
tools/regression/bin/sh/builtins/eval5.0
Normal file
@ -0,0 +1,4 @@
|
||||
# $FreeBSD$
|
||||
|
||||
# eval should return 0 if no command was executed.
|
||||
eval $(false)
|
Loading…
Reference in New Issue
Block a user