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

How to extract the substring array in shell script?

我正在尝试使用 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