1 #!/bin/bash
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 ### Blog Post Example
9 paths=`tr '\n' ':' | sed -e 's/:$//'`<<EOPATHS
10 /foo
11 /bar
12 /baz
13 EOPATHS
14 echo "$paths"
15 # stdout: /foo:/bar:/baz
16
17 ### Blog Post Example Fix
18 paths=`tr '\n' ':' | sed -e 's/:$//'<<EOPATHS
19 /foo
20 /bar
21 /baz
22 EOPATHS`
23 echo "$paths"
24 # stdout-json: "/foo\n/bar\n/baz\n"
25
26 ### Rewrite of Blog Post Example
27 paths=$(tr '\n' ':' | sed -e 's/:$//' <<EOPATHS
28 /foo
29 /bar
30 /baz
31 EOPATHS
32 )
33 echo "$paths"
34 # stdout-json: "/foo\n/bar\n/baz\n"