【发布时间】:2016-10-13 14:46:52
【问题描述】:
以下工作在 bsd unix、bash shell 中:
stuff=$(echo "dog cat rat")
read -r -a astuff <<< "$stuff"
for file in "${astuff[@]}"; do echo "file=$file"; done
显然包含<<< 的行将$stuff 分解为一个数组并将该数组放入astuff。但我不明白语法。 <<< 是否有手册页或其他文档?这如何在空格处破坏字符串?
【问题讨论】:
-
read将字符串围绕空格(更准确地说,围绕 $IFS 的字符)分割。 -
<<<引入了“此处字符串” - 在 the man page 上搜索。 -
This 是这里字符串的另一个很好的资源。
-
而且作业很经典useless use of
echo
标签: arrays bash shell variables