如何在shell脚本中提取子字符串数组?

如何在shell脚本中提取子字符串数组?,shell,sh,Shell,Sh,我试图使用shell脚本中的cut选项提取子字符串数组,但提取不正确。我使用下面的代码来提取子字符串数组 myval="one two three four" mysubstr=$(echo $myval| cut -d' ' -f 1,2,3,4) echo "${mysubstr[1]}" mysubstr现在正在打印空值。查看这是否有帮助: $ myval="one two three four" $ mysubstr=($myval) $ for i in ${mysubstr[@]}

我试图使用shell脚本中的
cut
选项提取子字符串数组,但提取不正确。我使用下面的代码来提取子字符串数组

myval="one two three four"
mysubstr=$(echo $myval| cut -d' ' -f 1,2,3,4)
echo "${mysubstr[1]}"
mysubstr
现在正在打印空值。

查看这是否有帮助:

$ myval="one two three four"
$ mysubstr=($myval)
$ for i in ${mysubstr[@]}; do echo $i; done
one
two
three
four

mysubstr
根本不是数组。这只是一根绳子。