OILS / spec / blog-other1.test.sh View on Github | oils.pub

66 lines, 13 significant
1## compare_shells: dash bash mksh zsh
2
3# From:
4#
5# https://lobste.rs/s/xhtim1/problems_with_shells_test_builtin_what
6# http://alangrow.com/blog/shell-quirk-assign-from-heredoc
7
8## suite: disabled
9
10#### Blog Post Example
11paths=`tr '\n' ':' | sed -e 's/:$//'`<<EOPATHS
12/foo
13/bar
14/baz
15EOPATHS
16echo "$paths"
17## stdout: /foo:/bar:/baz
18
19#### Blog Post Example Fix
20paths=`tr '\n' ':' | sed -e 's/:$//'<<EOPATHS
21/foo
22/bar
23/baz
24EOPATHS`
25echo "$paths"
26## STDOUT:
27/foo
28/bar
29/baz
30## END
31
32#### Rewrite of Blog Post Example
33paths=$(tr '\n' ':' | sed -e 's/:$//' <<EOPATHS
34/foo
35/bar
36/baz
37EOPATHS
38)
39echo "$paths"
40## STDOUT:
41/foo
42/bar
43/baz
44## END
45
46#### Simpler example
47foo=`cat`<<EOM
48hello world
49EOM
50echo "$foo"
51## stdout: hello world
52
53#### ` after here doc delimiter
54foo=`cat <<EOM
55hello world
56EOM`
57echo "$foo"
58## stdout: hello world
59
60#### ` on its own line
61foo=`cat <<EOM
62hello world
63EOM
64`
65echo "$foo"
66## stdout: hello world