Fix [, use \[ in tests.

This commit is contained in:
Jan Nieuwenhuizen 2018-12-04 20:15:53 +01:00
parent 179ae8cddd
commit 5b7f85aa3d
6 changed files with 17 additions and 17 deletions

View File

@ -317,7 +317,8 @@ Options:
(expression (expression
(pipeline (command expression))))) (pipeline (command expression)))))
((not (= (length files) 1)) ((not (= (length files) 1))
(format (current-error-port) "test: too many files: ~a\n" files) (format (current-error-port) "test: too many files: ~s\n" files)
(format (current-error-port) "test: command: ~s\n" args)
1) 1)
((option-ref options 'is-file #f) ((option-ref options 'is-file #f)
(regular-file? file)) (regular-file? file))
@ -343,16 +344,15 @@ Options:
(case-lambda (case-lambda
(() #f) (() #f)
(args (args
(lambda _ (cond ((and (pair? args) (equal? (car args) "--help"))
(cond ((and (pair? args) (equal? (car args) "--help")) (test-command "--help"))
(test-command "--help")) ((and (pair? args) (equal? (car args) "--version"))
((and (pair? args) (equal? (car args) "--version")) (test-command "--version"))
(test-command "--version")) (else
(else (if (not (equal? (last args) "]")) (begin
(if (not (equal? (last args) "]")) (begin (format (current-error-port) "gash: [: missing `]'\n")
(format (current-error-port) "gash: [: missing `]'\n") #f)
#f) (apply test-command (drop-right args 1))))))))
(apply test-command (drop-right args 1)))))))))
(define (term->string o) (define (term->string o)
(match o (match o

View File

@ -294,8 +294,8 @@
(('pipeline ('command ('word "shift"))) '(shift)) (('pipeline ('command ('word "shift"))) '(shift))
(('command ('word (or "[" "\\[") ('test-args test-args ...) "]")) (('command ('word (and (or "[" "\\[") bracket) ('test-args test-args ...) "]"))
`(command (word "[") ,@(map transform test-args) (word "]"))) `(command (word ,bracket) ,@(map transform test-args) (word "]")))
((h t ...) (map transform o)) ((h t ...) (map transform o))
(_ o))) (_ o)))

View File

@ -1,4 +1,4 @@
if [ 0 = 1 ]; then if \[ 0 = 1 ]; then
exit 1 exit 1
fi fi
exit 0 exit 0

View File

@ -1,4 +1,4 @@
if [ 1 = 1 ]; then if \[ 1 = 1 ]; then
exit 0 exit 0
fi fi
exit 1 exit 1

View File

@ -1,4 +1,4 @@
if [ x"$y" = x ]; then if \[ x"$y" = x ]; then
exit 0 exit 0
fi fi
exit 1 exit 1

View File

@ -1,4 +1,4 @@
if [ -f foo-bar ]; then if \[ -f foo-bar ]; then
exit 1 exit 1
fi fi