| 1 | ## our_shell: ysh
|
| 2 |
|
| 3 | #### ysh usage
|
| 4 |
|
| 5 | set +o errexit
|
| 6 |
|
| 7 | $[ENV.SH] --location-str foo.hay --location-start-line 42 -c 'echo ()' 2>err.txt
|
| 8 |
|
| 9 | cat err.txt | grep -o -- '-- foo.hay:42: Unexpected'
|
| 10 |
|
| 11 |
|
| 12 | # common idiom is to use -- to say it came from a file
|
| 13 | $[ENV.SH] --location-str '[ stdin ]' --location-start-line 10 -c 'echo "line 10";
|
| 14 | echo ()' 2>err.txt
|
| 15 |
|
| 16 | cat err.txt | fgrep -o -- '-- [ stdin ]:11: Unexpected'
|
| 17 |
|
| 18 | ## STDOUT:
|
| 19 | -- foo.hay:42: Unexpected
|
| 20 | line 10
|
| 21 | -- [ stdin ]:11: Unexpected
|
| 22 | ## END
|
| 23 |
|
| 24 | #### --debug-file
|
| 25 | var TMP = ENV.TMP
|
| 26 | $[ENV.SH] --debug-file $TMP/debug.txt -c 'true'
|
| 27 | grep 'Oils started with' $TMP/debug.txt >/dev/null && echo yes
|
| 28 | ## stdout: yes
|
| 29 |
|
| 30 | #### Filename quoting
|
| 31 |
|
| 32 | echo '(BAD' > no-quoting
|
| 33 | echo '(BAD' > 'with spaces.sh'
|
| 34 | echo '(BAD' > $'bad \xff'
|
| 35 |
|
| 36 | write -n '' > err.txt
|
| 37 |
|
| 38 | $[ENV.SH] no-quoting 2>>err.txt || true
|
| 39 | $[ENV.SH] 'with spaces.sh' 2>>err.txt || true
|
| 40 | $[ENV.SH] $'bad \xff' 2>>err.txt || true
|
| 41 |
|
| 42 | egrep --only-matching '^.*:1' err.txt
|
| 43 |
|
| 44 | ## STDOUT:
|
| 45 | no-quoting:1
|
| 46 | "with spaces.sh":1
|
| 47 | b'bad \yff':1
|
| 48 | ## END
|
| 49 |
|
| 50 |
|
| 51 | #### shopt --set verbose_errexit
|
| 52 |
|
| 53 | try {
|
| 54 | $[ENV.SH] -c '/bin/false' 2>on.txt
|
| 55 | }
|
| 56 |
|
| 57 | try {
|
| 58 | $[ENV.SH] +o verbose_errexit -c '/bin/false' 2>off.txt
|
| 59 | }
|
| 60 |
|
| 61 | wc -l on.txt off.txt
|
| 62 | #echo
|
| 63 | #cat on.txt off.txt
|
| 64 |
|
| 65 | ## STDOUT:
|
| 66 | 3 on.txt
|
| 67 | 0 off.txt
|
| 68 | 3 total
|
| 69 | ## END
|
| 70 |
|
| 71 | #### YSH shows options correctly (bug fix)
|
| 72 |
|
| 73 | $[ENV.SH] -o | egrep 'errexit|pipefail'
|
| 74 |
|
| 75 | ## STDOUT:
|
| 76 | set -o errexit
|
| 77 | set -o pipefail
|
| 78 | ## END
|
| 79 |
|
| 80 | #### --tool syntax-tree respects frontend/syntax_abbrev.py
|
| 81 |
|
| 82 | $[ENV.SH] --tool syntax-tree <<< '''
|
| 83 | echo 'sq'
|
| 84 | '''
|
| 85 |
|
| 86 | $[ENV.SH] --tool syntax-tree <<< '''
|
| 87 | echo "hi $x ${y}"
|
| 88 | '''
|
| 89 |
|
| 90 | $[ENV.SH] --tool syntax-tree <<< '''
|
| 91 | var x = 42 + a
|
| 92 | '''
|
| 93 |
|
| 94 | # this reflects the default width
|
| 95 |
|
| 96 | ## STDOUT:
|
| 97 | (C (w <Lit_Chars echo>) (w (SQ sq)))
|
| 98 | (C
|
| 99 | (w <Lit_Chars echo>)
|
| 100 | (w (DQ <Lit_Chars "hi "> ($ x) <Lit_Chars " "> (${ VSub_Name y)))
|
| 101 | )
|
| 102 | (command.VarDecl
|
| 103 | keyword:<KW_Var var>
|
| 104 | lhs:[(NameType left:<Expr_Name x> name:x)]
|
| 105 | rhs:(expr.Binary op:<Arith_Plus "+"> left:(Const Expr_DecInt _) right:(Var a))
|
| 106 | )
|
| 107 | ## END
|