1 ## our_shell: ysh
2
3 #### ysh usage
4
5 set +o errexit
6
7 $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 $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 $SH --debug-file $TMP/debug.txt -c 'true'
26 grep 'Oils started with' $TMP/debug.txt >/dev/null && echo yes
27 ## stdout: yes
28
29 #### Filename quoting
30
31 echo '(BAD' > no-quoting
32 echo '(BAD' > 'with spaces.sh'
33 echo '(BAD' > $'bad \xff'
34
35 write -n '' > err.txt
36
37 $SH no-quoting 2>>err.txt || true
38 $SH 'with spaces.sh' 2>>err.txt || true
39 $SH $'bad \xff' 2>>err.txt || true
40
41 egrep --only-matching '^.*:1' err.txt
42
43 ## STDOUT:
44 no-quoting:1
45 "with spaces.sh":1
46 b'bad \yff':1
47 ## END
48
49
50 #### shopt --set verbose_errexit
51
52 try {
53 $SH -c '/bin/false' 2>on.txt
54 }
55
56 try {
57 $SH +o verbose_errexit -c '/bin/false' 2>off.txt
58 }
59
60 wc -l on.txt off.txt
61 #echo
62 #cat on.txt off.txt
63
64 ## STDOUT:
65 3 on.txt
66 0 off.txt
67 3 total
68 ## END