echo as a value command

- echo gives its words as one string, and shadows the program.
- With -n, -e or -E it runs the program echo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Linus Björnstam 2026-12-01 07:29:10 +01:00
parent acd84a2a4c
commit 8ded734477
5 changed files with 36 additions and 10 deletions

View file

@ -70,7 +70,7 @@
(expect ">FILE 2>&1" (c (str "ls /no/such/dir >" file " 2>&1; grep -c such " file)) "1")
(expect "2>&1 before >" (c (str "ls 2>&1 >" file))
"err: bjosh: 2>&1 before > or >> is not supported yet: write >FILE 2>&1\ncode: 2")
(expect ">&2 is not supported yet" (c "echo x >&2")
(expect ">&2 is not supported yet" (c "printf x >&2")
"err: bjosh: >&2 is not supported yet\ncode: 2")
;; Shell commands.

View file

@ -117,6 +117,13 @@
(expect "jobs in a pipe, without jobs" (c "jobs | n") "0")
(expect "history in a pipe, without an editor" (c "history | n") "0")
;; echo.
(expect "echo is a value command" (c "type echo") "echo is a value command: echo, echo")
(expect "echo: its words as one string" (c "echo a b | n") "1")
(expect "echo with no words" (c "echo | wc -c") "1")
(expect "echo -n is the program" (c "echo -n x | wc -c") "1")
(expect "echo > a file" (c "echo hi > e.txt; cat e.txt") "hi")
;; Names (decision 4).
(expect "a long name that is a program runs the program" (c "printf 'a\\na\\n' | uniq -c") " 2 a")
(expect "a short name is always the value command" (c "type u") "u is a value command: uniq, u")