implement shift.

This commit is contained in:
Jan Nieuwenhuizen 2018-11-25 08:46:10 +01:00
parent 2f5de56cfd
commit 7f6b88c43b
6 changed files with 28 additions and 0 deletions

View File

@ -17,6 +17,7 @@ tests='
01-script-backslash-twice
01-script-$0
01-script-$@
01-script-shift
03-echo
03-echo-doublequotes

View File

@ -54,6 +54,7 @@
jobs-command
pwd-command
set-command
shift-command
))
(define (PATH-search-path program)
@ -118,6 +119,12 @@
(apply set-command (map (cut string-append set <>) (cdr lst)))))
((h ...) (last (map set-command args)))))
(define (shift-command . args)
(lambda _
(match args
(() (when (pair? (cdr (%command-line)))
(%command-line (cons (car (%command-line)) (cddr (%command-line)))))))))
(define (eval-command . args)
(lambda _
(match args
@ -379,6 +386,7 @@ Options:
("jobs" . ,jobs-command)
("pwd" . ,pwd-command)
("set" . ,set-command)
("shift" . ,shift-command)
("test" . ,test-command)
("type" . ,type-command)
("[" . ,bracket-command)

View File

@ -283,5 +283,7 @@
(('word 'delim) '(word ""))
(('pipeline ('command ('word "shift"))) '(shift))
((h t ...) (map transform o))
(_ o)))

View File

@ -426,3 +426,6 @@
(define (test . o) ;; TODO replace with implementation in scheme
(command (cons "test" o)))
(define (shift . o)
(apply (shift-command) o))

9
test/01-script-shift.sh Normal file
View File

@ -0,0 +1,9 @@
echo $@
shift
echo $@
shift
echo $@
shift
echo $@
shift
echo $@

View File

@ -0,0 +1,5 @@
-s --long file0 file1
--long file0 file1
file0 file1
file1