How can I disable word-splitting during command substitution? Here's a simplified example of the problem:
4:00PM /Users/paymahn/Downloads ❯❯❯ cat test.txt hello\nworld 4:00PM /Users/paymahn/Downloads ❯❯❯ echo $(cat test.txt ) hello world 4:00PM /Users/paymahn/Downloads ❯❯❯ echo "$(cat test.txt )" hello world 4:01PM /Users/paymahn/Downloads ❯❯❯ echo "$(cat "test.txt" )" hello world
What I want is for echo $(cat test.txt)
(or some variant of that which includes command subsitution) to output hello\nworld
.
I found https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html which says at the bottom If the substitution appears within double quotes, word splitting and filename expansion are not performed on the results.
but I can't seem to make sense of that. I would have thought that one of the examples I already tried conformed to that rule but I guess not.
echo $BASH_VERSION
? – ilkkachu Aug 22 '18 at 20:12hexdump -C test.txt
. – RalfFriedl Aug 22 '18 at 20:14