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

View File

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

View File

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

View File

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

View File

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

View File

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