| 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
|
| 11 | paths=`tr '\n' ':' | sed -e 's/:$//'`<<EOPATHS
|
| 12 | /foo
|
| 13 | /bar
|
| 14 | /baz
|
| 15 | EOPATHS
|
| 16 | echo "$paths"
|
| 17 | ## stdout: /foo:/bar:/baz
|
| 18 |
|
| 19 | #### Blog Post Example Fix
|
| 20 | paths=`tr '\n' ':' | sed -e 's/:$//'<<EOPATHS
|
| 21 | /foo
|
| 22 | /bar
|
| 23 | /baz
|
| 24 | EOPATHS`
|
| 25 | echo "$paths"
|
| 26 | ## STDOUT:
|
| 27 | /foo
|
| 28 | /bar
|
| 29 | /baz
|
| 30 | ## END
|
| 31 |
|
| 32 | #### Rewrite of Blog Post Example
|
| 33 | paths=$(tr '\n' ':' | sed -e 's/:$//' <<EOPATHS
|
| 34 | /foo
|
| 35 | /bar
|
| 36 | /baz
|
| 37 | EOPATHS
|
| 38 | )
|
| 39 | echo "$paths"
|
| 40 | ## STDOUT:
|
| 41 | /foo
|
| 42 | /bar
|
| 43 | /baz
|
| 44 | ## END
|
| 45 |
|
| 46 | #### Simpler example
|
| 47 | foo=`cat`<<EOM
|
| 48 | hello world
|
| 49 | EOM
|
| 50 | echo "$foo"
|
| 51 | ## stdout: hello world
|
| 52 |
|
| 53 | #### ` after here doc delimiter
|
| 54 | foo=`cat <<EOM
|
| 55 | hello world
|
| 56 | EOM`
|
| 57 | echo "$foo"
|
| 58 | ## stdout: hello world
|
| 59 |
|
| 60 | #### ` on its own line
|
| 61 | foo=`cat <<EOM
|
| 62 | hello world
|
| 63 | EOM
|
| 64 | `
|
| 65 | echo "$foo"
|
| 66 | ## stdout: hello world
|