Do here-strings undergo word-splitting?

不羁的心 提交于 2020-07-18 08:50:05

问题


Quoting Bash Reference Manual and man bash (version 4.3):

[n]<<< word

The word undergoes brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal. Pathname expansion and word splitting are not performed.

The word should not undergo word-splitting. However, using this simple code:

var="a    b"

cat <<< $var
#output:
#a b

cat <<< "$var"
#output:
#a    b

What am I missing? Does this depend on the version of bash or is there a mistake in the manual? I am using GNU bash, version 4.3.48.


回答1:


The change from splitting here-strings to not splitting them happened between bash-4.4-alpha and bash-4.4-beta. Quoting from CHANGES:

Bash no longer splits the expansion of here-strings, as the documentation has always said.

So the manuals of older Bash versions mentioned it, but didn't actually do it.



来源:https://stackoverflow.com/questions/47744854/do-here-strings-undergo-word-splitting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!