庆典词的拆分机制 [英] bash word splitting mechanism
问题描述
我是新来Bash和我看到有被Bash进行自动分词:
I am new to Bash and I am seeing that there is automatic word splitting done by Bash:
a="1 2 3 4"
如果我回声是由回声$ A
我 1 2 3 4
,它已经做字分裂含蓄。如果通过一个我环,我分别得到1,2,3和4。
If I echo "a" by echo $a
I got 1 2 3 4
, which has done word splitting implicitly. If I loop through "a", I got 1, 2, 3, and 4 respectively.
我也是从这里读>是
外壳扫描参数扩展的结果,命令
替换和算术扩展未发生内
双引号的字分割。
The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting.
而且我还发现,如果我有
And I also found that if I have
b=$a;
echo "$b"
我会得到
"1 2 3 4"
所以,这里是我的问题:当在分词做了什么?它改变字符串本身?当我使用它才生效回声
或为
(循环)?更一般的,如何处理bash的它在地球上?
So, here is my problem: when is the word splitting done? does it change the string itself? Does it only take effect when I use echo
or for
(loop)? More general, how does bash handle it on earth?
十分感谢!
推荐答案
读男人庆典
。对于分配,它说:
所有的值进行波浪线扩展,参数和变量扩展,命令替换,算术扩展和引用删除[...]在特殊参数下解释不进行词的拆分,以$ @的例外。不执行路径扩展。
All values undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal [ ... ] Word splitting is not performed, with the exception of "$@" as explained below under Special Parameters. Pathname expansion is not performed.
词的拆分也在 [[]]
情况不会发生:
Word splitting also does not happen in [[ ]]
conditions:
词的拆分和路径的扩展之间不上话进行的[[和]]
Word splitting and pathname expansion are not performed on the words between the [[ and ]]
这篇关于庆典词的拆分机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!