2009年(48)
分类:
2009-09-17 18:38:29
here string可以看成是here document的一种定制形式. 除了COMMAND <<<$WORD, 就什么都没有了, $WORD
将被扩展并且被送入COMMAND
的stdin中.
1 String="This is a string of words." 2 3 read -r -a Words <<< "$String" 4 # "read"命令的-a选项 5 #+ 将会把结果值按顺序的分配给数组中的每一项. 6 7 echo "First word in String is: ${Words[0]}" # This 8 echo "Second word in String is: ${Words[1]}" # is 9 echo "Third word in String is: ${Words[2]}" # a 10 echo "Fourth word in String is: ${Words[3]}" # string 11 echo "Fifth word in String is: ${Words[4]}" # of 12 echo "Sixth word in String is: ${Words[5]}" # words. 13 echo "Seventh word in String is: ${Words[6]}" # (null) 14 # $String的结尾. 15 16 # 感谢, Francisco Lobo的这个建议. |