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