1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

test foo =~ foo should fail with exit status 2 (#245)

When test is passed the '=~' operator, it will silently fail with
exit status 1:
    $ test foo =~ foo; echo $?
    1
This bug is caused by test_binop reaching the 'NOTREACHED' area of
code. The bugfix was adapted from ksh2020:
https://github.com/att/ast/issues/1152

src/cmd/ksh93/bltins/test.c: test_binop():
- Error out with a message suggesting usage of '[[ ... ]]' if '=~'
  is passed to the test builtin.
- Special-case TEST_END (']]') as that is not really an operator.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-03-27 14:51:16 -07:00 committed by GitHub
parent 767d23b3fe
commit fc2d5a6019
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 6 deletions

View file

@ -20,7 +20,7 @@
#pragma prototyped
/*
* tables for the test builtin [[...]] and [...]
* tables for the test builtin [[ ... ]] and [ ... ]
*/
#include <ast.h>
@ -29,7 +29,7 @@
#include "test.h"
/*
* This is the list of binary test and [[...]] operators
* This is the list of binary test and [[ ... ]] operators
*/
const Shtable_t shtab_testops[] =
@ -166,5 +166,6 @@ const char test_opchars[] = "HLNRSVOGCaeohrwxdcbfugkv"
const char e_argument[] = "argument expected";
const char e_missing[] = "%s missing";
const char e_badop[] = "%s: unknown operator";
const char e_unsupported_op[] = "%s: operator not supported; use [[ ... ]]";
const char e_tstbegin[] = "[[ ! ";
const char e_tstend[] = " ]]\n";