"<<<"的文档在bash shell中

时间:2016-10-13 14:46:52

标签: arrays bash shell variables

以下适用于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中。但我不懂语法。是否有<<<的手册页或其他文档?这是如何在空格中打破字符串的?

3 个答案:

答案 0 :(得分:4)

它在这里称为字符串。您可以阅读here

  

这里的字符串          这里文档的变体,格式为:

          [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 result is supplied as a single string, with a newline
   appended, to the command on its standard input (or file descriptor n
   if n is specified).

答案 1 :(得分:1)

<<<

... read -r -a astuff <<EOF $stuff EOF 是“here-string”语法,语法糖提供了一种更短的写法:

read
因此,

astuff是负责将您的内容分配到-a的命令; IFS参数告诉它将read中的字符(默认情况下,空格,制表符和换行符)拆分为数组。

参考文献:

......以及int PASCAL CppFunction( BYTE *pbAdapterID, BYTE *pbTargetID, char *pcVendor, char *pcProduct, char *pcRelease, int iMessageBox); 组件:

答案 2 :(得分:0)

您可以搜索 $ man bash | grep -A10 -B4 "<<<" 以获取解释。这是一种可能的方式:

grep

man bash为“&lt;&lt;&lt;&lt;”在 Here Strings A variant of here documents, the format is: <<<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 per‐ formed. The result is supplied as a single string to the command on its standard input. 的输出中,显示在包含“&lt;&lt;&lt;&lt;”的行旁边在该行之前还有4行,之后是10行。在我的Debian上,我得到了这个结果:

r<-data.frame(o=runif(n = 50),m=rep(c("A","N"),25))
te<-data.frame(o=runif(n = 50),m=rep(c("G","H"),25))
aq<-list(f=list(df=r,g=0),g2=list(df=te,g=5))

还有3条线,它们是无关的。

您可以重复搜索其他单词和您不理解的“单词”。