mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-30 15:02:18 +01:00
42031 + 42048: Make [[ -o invalidoption ]] a normal(ish) false value, rather than a syntax error.
This commit is contained in:
parent
487489c522
commit
77a39b57bf
6 changed files with 58 additions and 7 deletions
|
@ -1,3 +1,9 @@
|
|||
2017-11-24 Daniel Shahaf <d.s@daniel.shahaf.name>
|
||||
|
||||
* 42031 + 42048: Doc/Zsh/cond.yo, Doc/Zsh/options.yo, README,
|
||||
Src/cond.c, Test/C02cond.ztst: Make [[ -o invalidoption ]]
|
||||
a normal(ish) false value, rather than a syntax error.
|
||||
|
||||
2017-11-20 Peter Stephenson <p.stephenson@samsung.com>
|
||||
|
||||
* Dima Kogan: 42040: Src/glob.c: buffer for glob qualifiers
|
||||
|
|
|
@ -45,6 +45,10 @@ item(tt(-o) var(option))(
|
|||
true if option named var(option) is on. var(option)
|
||||
may be a single character, in which case it is a single letter option name.
|
||||
(See noderef(Specifying Options).)
|
||||
|
||||
When no option named var(option) exists, and the tt(POSIX_BUILTINS) option
|
||||
hasn't been set, return 3 with a warning. If that option is set, return 1
|
||||
with no warning.
|
||||
)
|
||||
item(tt(-p) var(file))(
|
||||
true if var(file) exists and is a FIFO special file (named pipe).
|
||||
|
|
|
@ -2169,6 +2169,9 @@ command found in the path.
|
|||
Furthermore, the tt(getopts) builtin behaves in a POSIX-compatible
|
||||
fashion in that the associated variable tt(OPTIND) is not made
|
||||
local to functions.
|
||||
|
||||
Moreover, the warning and special exit code from
|
||||
tt([[ -o )var(non_existent_option)tt( ]]) are suppressed.
|
||||
)
|
||||
pindex(POSIX_IDENTIFIERS)
|
||||
pindex(NO_POSIX_IDENTIFIERS)
|
||||
|
|
12
README
12
README
|
@ -54,6 +54,18 @@ foo=([aeiou]\=vowel)
|
|||
This is only required for array values contained within parentheses;
|
||||
command line expansion for normal arguments has not changed.
|
||||
|
||||
3) The syntax
|
||||
|
||||
[[ -o foo ]]
|
||||
|
||||
where foo is not the name of a shell option (with optional underscores
|
||||
and optional "no" prefix) used to be treated as a syntax error, i.e.,
|
||||
the enclosing command line or file were aborted. It now emits a warning
|
||||
and returns a non-zero exit code. For further details, see the
|
||||
documentation of the -o switch in the chapter "Conditional Expressions"
|
||||
in the zshmisc(1) manual.
|
||||
|
||||
|
||||
Incompatibilities between 5.3.1 and 5.4.2
|
||||
-----------------------------------------
|
||||
|
||||
|
|
20
Src/cond.c
20
Src/cond.c
|
@ -61,7 +61,8 @@ static void cond_subst(char **strp, int glob_ok)
|
|||
* of functionality.
|
||||
*
|
||||
* Return status is the final shell status, i.e. 0 for true,
|
||||
* 1 for false and 2 for error.
|
||||
* 1 for false, 2 for syntax error, 3 for "option in tested in
|
||||
* -o does not exist".
|
||||
*/
|
||||
|
||||
/**/
|
||||
|
@ -86,10 +87,10 @@ evalcond(Estate state, char *fromtest)
|
|||
if (tracingcond)
|
||||
fprintf(xtrerr, " %s", condstr[ctype]);
|
||||
ret = evalcond(state, fromtest);
|
||||
if (ret == 2)
|
||||
return ret;
|
||||
else
|
||||
if (ret == 0 || ret == 1)
|
||||
return !ret;
|
||||
else
|
||||
return ret;
|
||||
case COND_AND:
|
||||
if (!(ret = evalcond(state, fromtest))) {
|
||||
if (tracingcond)
|
||||
|
@ -100,7 +101,8 @@ evalcond(Estate state, char *fromtest)
|
|||
return ret;
|
||||
}
|
||||
case COND_OR:
|
||||
if ((ret = evalcond(state, fromtest)) == 1) {
|
||||
ret = evalcond(state, fromtest);
|
||||
if (ret == 1 || ret == 3) {
|
||||
if (tracingcond)
|
||||
fprintf(xtrerr, " %s", condstr[ctype]);
|
||||
goto rec;
|
||||
|
@ -506,8 +508,12 @@ optison(char *name, char *s)
|
|||
else
|
||||
i = optlookup(s);
|
||||
if (!i) {
|
||||
zwarnnam(name, "no such option: %s", s);
|
||||
return 2;
|
||||
if (isset(POSIXBUILTINS))
|
||||
return 1;
|
||||
else {
|
||||
zwarnnam(name, "no such option: %s", s);
|
||||
return 3;
|
||||
}
|
||||
} else if(i < 0)
|
||||
return !unset(-i);
|
||||
else
|
||||
|
|
|
@ -440,6 +440,26 @@ F:Failures in these cases do not indicate a problem in the shell.
|
|||
> [[ 'a' == 'b' || 'b' = 'c' || 'c' != 'd' ]]
|
||||
>}
|
||||
|
||||
(setopt posixbuiltins; [[ -o invalidoption ]]; echo set: $?; echo "line 1: no warning" >&2)
|
||||
(unsetopt posixbuiltins; [[ -o invalidoption ]]; echo unset: $?)
|
||||
[[ -o invalidoption || -n nonempty ]]; echo "in disjunction, true: $?"
|
||||
[[ -o invalidoption || -z nonempty ]]; echo "in disjunction, false: $?"
|
||||
[[ ! -o invalidoption ]]; echo "negated: $?"
|
||||
[[ -o invalidoption && -n nonempty ]] || echo "in conjunction: $?"
|
||||
0:-o invalidoption
|
||||
>set: 1
|
||||
?line 1: no warning
|
||||
>unset: 3
|
||||
?(eval):2: no such option: invalidoption
|
||||
>in disjunction, true: 0
|
||||
?(eval):3: no such option: invalidoption
|
||||
>in disjunction, false: 1
|
||||
?(eval):4: no such option: invalidoption
|
||||
>negated: 3
|
||||
?(eval):5: no such option: invalidoption
|
||||
>in conjunction: 3
|
||||
?(eval):6: no such option: invalidoption
|
||||
|
||||
%clean
|
||||
# This works around a bug in rm -f in some versions of Cygwin
|
||||
chmod 644 unmodish
|
||||
|
|
Loading…
Reference in a new issue