aboutsummaryrefslogtreecommitdiff
path: root/coreutils/test.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-14 19:42:12 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-14 19:42:12 +0200
commit82a6fb3ea6b49bcf1ef21ab589179ee2d6ffdc09 (patch)
treeeb8ffd6fcf3a111f5392ecb47a6ad45401ae6d82 /coreutils/test.c
parent2441060bebec2d65c9d106335223f37ec6e8ea5b (diff)
downloadbusybox-w32-82a6fb3ea6b49bcf1ef21ab589179ee2d6ffdc09.tar.gz
busybox-w32-82a6fb3ea6b49bcf1ef21ab589179ee2d6ffdc09.tar.bz2
busybox-w32-82a6fb3ea6b49bcf1ef21ab589179ee2d6ffdc09.zip
ash: fix . builtin
Also, move [[ ]] comment to test.c and expand it Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/test.c')
-rw-r--r--coreutils/test.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index cfaf4ca5d..73048d311 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -19,7 +19,6 @@
19 * Original copyright notice states: 19 * Original copyright notice states:
20 * "This program is in the Public Domain." 20 * "This program is in the Public Domain."
21 */ 21 */
22
23#include "libbb.h" 22#include "libbb.h"
24#include <setjmp.h> 23#include <setjmp.h>
25 24
@@ -29,7 +28,6 @@
29 * This is true regardless of PREFER_APPLETS and STANDALONE_SHELL 28 * This is true regardless of PREFER_APPLETS and STANDALONE_SHELL
30 * state. */ 29 * state. */
31 30
32
33/* test(1) accepts the following grammar: 31/* test(1) accepts the following grammar:
34 oexpr ::= aexpr | aexpr "-o" oexpr ; 32 oexpr ::= aexpr | aexpr "-o" oexpr ;
35 aexpr ::= nexpr | nexpr "-a" aexpr ; 33 aexpr ::= nexpr | nexpr "-a" aexpr ;
@@ -47,6 +45,50 @@
47 operand ::= <any legal UNIX file name> 45 operand ::= <any legal UNIX file name>
48*/ 46*/
49 47
48/* TODO: handle [[ expr ]] bashism bash-compatibly.
49 * [[ ]] is meant to be a "better [ ]", with less weird syntax
50 * and without the risk of variables and quoted strings misinterpreted
51 * as operators.
52 * This will require support from shells - we need to know quote status
53 * of each parameter (see below).
54 *
55 * Word splitting and pathname expansion should NOT be performed:
56 * # a="a b"; [[ $a = "a b" ]] && echo YES
57 * YES
58 * # [[ /bin/m* ]] && echo YES
59 * YES
60 *
61 * =~ should do regexp match
62 * = and == should do pattern match against right side:
63 * # [[ *a* == bab ]] && echo YES
64 * # [[ bab == *a* ]] && echo YES
65 * YES
66 * != does the negated == (i.e., also with pattern matching).
67 * Pattern matching is quotation-sensitive:
68 * # [[ bab == "b"a* ]] && echo YES
69 * YES
70 * # [[ bab == b"a*" ]] && echo YES
71 *
72 * Conditional operators such as -f must be unquoted literals to be recognized:
73 * # [[ -e /bin ]] && echo YES
74 * YES
75 * # [[ '-e' /bin ]] && echo YES
76 * bash: conditional binary operator expected...
77 * # A='-e'; [[ $A /bin ]] && echo YES
78 * bash: conditional binary operator expected...
79 *
80 * || and && should work as -o and -a work in [ ]
81 * -a and -o aren't recognized (&& and || are to be used instead)
82 * ( and ) do not need to be quoted unlike in [ ]:
83 * # [[ ( abc ) && '' ]] && echo YES
84 * # [[ ( abc ) || '' ]] && echo YES
85 * YES
86 * # [[ ( abc ) -o '' ]] && echo YES
87 * bash: syntax error in conditional expression...
88 *
89 * Apart from the above, [[ expr ]] should work as [ expr ]
90 */
91
50#define TEST_DEBUG 0 92#define TEST_DEBUG 0
51 93
52enum token { 94enum token {