current_processes=`ps aux | grep "tempdir" | tail -3`
当我回应它时,它看起来像这样
echo $current_processes 19984 10089 17784
当我回声加双引号时,它看起来像这样:
echo "$current_processes" 19984 10089 17784
当我使用双引号但没有双引号时,为什么它会将这些放在新行上?
解决方法
Word Splitting
The shell scans the results of parameter expansion,command substitution,and arithmetic expansion that did not occur within@H_301_24@ double quotes for word splitting.
The shell treats each character of IFS as a delimiter,and splits the@H_301_24@ results of the other expansions into words on these characters. If IFS@H_301_24@ is unset,or its value is exactly,the default,@H_301_24@ then any sequence of IFS characters serves to delimit words. If IFS@H_301_24@ has a value other than the default,then sequences of the whitespace@H_301_24@ characters space and tab are ignored at the beginning and end of the@H_301_24@ word,as long as the whitespace character is in the value of IFS (an@H_301_24@ IFS whitespace character). Any character in IFS that is not IFS white-@H_301_24@ space,along with any adjacent IFS whitespace characters,delimits a@H_301_24@ field. A sequence of IFS whitespace characters is also treated as a@H_301_24@ delimiter. If the value of IFS is null,no word splitting occurs.
您可以使用echo“$IFS”|查看IFS的内容XXD.它会告诉你
00000000: 2009 0a0a ...
这意味着空格(0x20),制表符(0x09)和换行符(0x0a).第二个0x0a来自echo命令.
您可以通过将IFS设置为空字符串来避免此替换:
IFS="" echo "$current_processes" 19984 10089 17784
但我不建议这样做.