Support . script, source script.

This commit is contained in:
Jan Nieuwenhuizen 2018-11-10 10:25:02 +01:00
parent 726ca052a9
commit 90325b22a2
5 changed files with 17 additions and 1 deletions

View File

@ -64,6 +64,8 @@ tests="
40-eval-echo-variable
40-assignment-eval-echo
41-dot.sh
50-iohere
60-function

View File

@ -362,6 +362,8 @@
(('brace-group o) `(brace-group ,(transform o)))
(('file-name o) `(file-name ,(transform o)))
('doublequotes "")
(_ ast)))

View File

@ -89,7 +89,13 @@
escape-builtin?))
(lambda _ (status:exit-val (apply system* command))))))
(else (lambda () #t))))
(exec (append-map glob args)))
(match args
(((or "." "source") file-name)
(let* ((string (with-input-from-file file-name read-string))
(ast (parse-string string)))
(run ast)
0))
(_ (exec (append-map glob args)))))
(define (glob? pattern)
(and (string? pattern) (string-match "\\?|\\*" pattern)))
@ -342,6 +348,9 @@
(if (string-suffix? pattern value) (substring value 0 (string-length pattern))
value))))
(define (number o)
o)
(define (pat o)
o)

2
test/41-dot.sh Normal file
View File

@ -0,0 +1,2 @@
. test/data/script.sh
echo $foo

1
test/data/script.sh Normal file
View File

@ -0,0 +1 @@
foo=bar