diff options
author | jilles <jilles@FreeBSD.org> | 2010-03-06 16:57:53 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2010-03-06 16:57:53 +0000 |
commit | 1bfbe947abf36034bc4aa54fb61824fb8153e43f (patch) | |
tree | a292cee82566850ab924f6b484d9ac29b205226d /tools | |
parent | ce168ed4ea9ae18aa7997ba001e291cd5b2d3c8b (diff) | |
download | FreeBSD-src-1bfbe947abf36034bc4aa54fb61824fb8153e43f.zip FreeBSD-src-1bfbe947abf36034bc4aa54fb61824fb8153e43f.tar.gz |
sh: Improve the command builtin:
* avoid unnecessary fork
* allow executing builtins via command
* executing a special builtin via command removes its special properties
Obtained from: NetBSD (parts)
Diffstat (limited to 'tools')
-rw-r--r-- | tools/regression/bin/sh/builtins/command8.0 | 45 | ||||
-rw-r--r-- | tools/regression/bin/sh/builtins/var-assign2.0 | 55 | ||||
-rw-r--r-- | tools/regression/bin/sh/errors/redirection-error3.0 | 54 |
3 files changed, 154 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/builtins/command8.0 b/tools/regression/bin/sh/builtins/command8.0 new file mode 100644 index 0000000..949ffed --- /dev/null +++ b/tools/regression/bin/sh/builtins/command8.0 @@ -0,0 +1,45 @@ +# $FreeBSD$ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift 0,\ + times,\ + trap,\ + unset foo" + +set -e + +# Check that special builtins can be executed via "command". + +set -- ${SPECIAL} +for cmd in "$@" +do + sh -c "v=:; while \$v; do v=false; command ${cmd}; done" >/dev/null +done + +while :; do + command break + echo Error on line $LINENO +done + +set p q r +command shift 2 +if [ $# -ne 1 ]; then + echo Error on line $LINENO +fi + +( + command exec >/dev/null + echo Error on line $LINENO +) + +set +e +! command shift 2 2>/dev/null diff --git a/tools/regression/bin/sh/builtins/var-assign2.0 b/tools/regression/bin/sh/builtins/var-assign2.0 new file mode 100644 index 0000000..8485df8 --- /dev/null +++ b/tools/regression/bin/sh/builtins/var-assign2.0 @@ -0,0 +1,55 @@ +# $FreeBSD$ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift 0,\ + times,\ + trap,\ + unset foo" + +UTILS="alias,\ + bg,\ + bind,\ + cd,\ + command echo,\ + echo,\ + false,\ + fc -l,\ + fg,\ + getopts a var,\ + hash,\ + jobs,\ + printf a,\ + pwd,\ + read var < /dev/null,\ + test,\ + true,\ + type ls,\ + ulimit,\ + umask,\ + unalias -a,\ + wait" + +set -e + +# With 'command', variable assignments affect the shell environment. + +set -- ${SPECIAL} +for cmd in "$@" +do + sh -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1 +done + +set -- ${UTILS} +for cmd in "$@" +do + sh -c "VAR=0; VAR=1 command ${cmd}; exit \${VAR}" >/dev/null 2>&1 +done diff --git a/tools/regression/bin/sh/errors/redirection-error3.0 b/tools/regression/bin/sh/errors/redirection-error3.0 new file mode 100644 index 0000000..93f526c --- /dev/null +++ b/tools/regression/bin/sh/errors/redirection-error3.0 @@ -0,0 +1,54 @@ +# $FreeBSD$ +IFS=, + +SPECIAL="break,\ + :,\ + continue,\ + . /dev/null,\ + eval,\ + exec,\ + export -p,\ + readonly -p,\ + set,\ + shift,\ + times,\ + trap,\ + unset foo" + +UTILS="alias,\ + bg,\ + bind,\ + cd,\ + command echo,\ + echo,\ + false,\ + fc -l,\ + fg,\ + getopts a -a,\ + hash,\ + jobs,\ + printf a,\ + pwd,\ + read var < /dev/null,\ + test,\ + true,\ + type ls,\ + ulimit,\ + umask,\ + unalias -a,\ + wait" + +# When used with 'command', neither special built-in utilities nor other +# utilities must abort on a redirection error. + +set -- ${SPECIAL} +for cmd in "$@" +do + sh -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1 +done + +set -- ${UTILS} +for cmd in "$@" +do + sh -c "command ${cmd} > /; exit 0" 2>/dev/null || exit 1 +done |