diff options
-rw-r--r-- | coreutils/test.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/coreutils/test.c b/coreutils/test.c index a09f7e6ec..f86176168 100644 --- a/coreutils/test.c +++ b/coreutils/test.c @@ -182,21 +182,26 @@ static void initialize_group_array(void); int bb_test(int argc, char **argv) { int res; - - if (LONE_CHAR(argv[0], '[')) { - --argc; - if (NOT_LONE_CHAR(argv[argc], ']')) { - bb_error_msg("missing ]"); - return 2; - } - argv[argc] = NULL; - } else if (strcmp(argv[0], "[[") == 0) { - --argc; - if (strcmp(argv[argc], "]]")) { - bb_error_msg("missing ]]"); - return 2; + char *arg0; + + arg0 = strrchr(argv[0], '/'); + if (!arg0++) arg0 = argv[0]; + if (arg0[0] == '[') { + if (!arg0[1]) { /* "[" ? */ + --argc; + if (NOT_LONE_CHAR(argv[argc], ']')) { + bb_error_msg("missing ]"); + return 2; + } + argv[argc] = NULL; + } else if (LONE_CHAR(arg0, '[') == 0) { /* "[[" ? */ + --argc; + if (strcmp(argv[argc], "]]") != 0) { + bb_error_msg("missing ]]"); + return 2; + } + argv[argc] = NULL; } - argv[argc] = NULL; } res = setjmp(leaving); |