1 | ## compare_shells: dash bash mksh zsh ash
|
2 |
|
3 | #### Parsing shell words \r \v
|
4 |
|
5 | # frontend/lexer_def.py has rules for this
|
6 |
|
7 | tab=$(python2 -c 'print "argv.py -\t-"')
|
8 | cr=$(python2 -c 'print "argv.py -\r-"')
|
9 | vert=$(python2 -c 'print "argv.py -\v-"')
|
10 | ff=$(python2 -c 'print "argv.py -\f-"')
|
11 |
|
12 | $SH -c "$tab"
|
13 | $SH -c "$cr"
|
14 | $SH -c "$vert"
|
15 | $SH -c "$ff"
|
16 |
|
17 | ## STDOUT:
|
18 | ['-', '-']
|
19 | ['-\r-']
|
20 | ['-\x0b-']
|
21 | ['-\x0c-']
|
22 | ## END
|
23 |
|
24 | #### \r in arith expression is allowed by some shells, but not most!
|
25 |
|
26 | arith=$(python2 -c 'print "argv.py $(( 1 +\n2))"')
|
27 | arith_cr=$(python2 -c 'print "argv.py $(( 1 +\r\n2))"')
|
28 |
|
29 | $SH -c "$arith"
|
30 | if test $? -ne 0; then
|
31 | echo 'failed'
|
32 | fi
|
33 |
|
34 | $SH -c "$arith_cr"
|
35 | if test $? -ne 0; then
|
36 | echo 'failed'
|
37 | fi
|
38 |
|
39 | ## STDOUT:
|
40 | ['3']
|
41 | failed
|
42 | ## END
|
43 |
|
44 | ## OK mksh/ash/osh STDOUT:
|
45 | ['3']
|
46 | ['3']
|
47 | ## END
|
48 |
|
49 | #### whitespace in string to integer conversion
|
50 |
|
51 | tab=$(python2 -c 'print "\t42\t"')
|
52 | cr=$(python2 -c 'print "\r42\r"')
|
53 |
|
54 | $SH -c 'echo $(( $1 + 1 ))' dummy0 "$tab"
|
55 | if test $? -ne 0; then
|
56 | echo 'failed'
|
57 | fi
|
58 |
|
59 | $SH -c 'echo $(( $1 + 1 ))' dummy0 "$cr"
|
60 | if test $? -ne 0; then
|
61 | echo 'failed'
|
62 | fi
|
63 |
|
64 | ## STDOUT:
|
65 | 43
|
66 | failed
|
67 | ## END
|
68 |
|
69 | ## OK mksh/ash/osh STDOUT:
|
70 | 43
|
71 | 43
|
72 | ## END
|
73 |
|
74 | #### \r at end of line is not special
|
75 |
|
76 | # hm I wonder if Windows ports have rules for this?
|
77 |
|
78 | cr=$(python2 -c 'print "argv.py -\r"')
|
79 |
|
80 | $SH -c "$cr"
|
81 |
|
82 | ## STDOUT:
|
83 | ['-\r']
|
84 | ## END
|
85 |
|
86 | #### Default IFS does not include \r \v \f
|
87 |
|
88 | # dash and zsh don't have echo -e
|
89 | tab=$(python2 -c 'print "-\t-"')
|
90 | cr=$(python2 -c 'print "-\r-"')
|
91 | vert=$(python2 -c 'print "-\v-"')
|
92 | ff=$(python2 -c 'print "-\f-"')
|
93 |
|
94 | $SH -c 'argv.py $1' dummy0 "$tab"
|
95 | $SH -c 'argv.py $1' dummy0 "$cr"
|
96 | $SH -c 'argv.py $1' dummy0 "$vert"
|
97 | $SH -c 'argv.py $1' dummy0 "$ff"
|
98 |
|
99 | ## STDOUT:
|
100 | ['-', '-']
|
101 | ['-\r-']
|
102 | ['-\x0b-']
|
103 | ['-\x0c-']
|
104 | ## END
|
105 |
|
106 | # No word splitting in zsh
|
107 |
|
108 | ## OK zsh STDOUT:
|
109 | ['-\t-']
|
110 | ['-\r-']
|
111 | ['-\x0b-']
|
112 | ['-\x0c-']
|
113 | ## END
|
114 |
|