bash数组来自find命令长度

fmo*_*lia 5 arrays size shell

我有以下代码:

filelist="$(find $name -type f | sort)";
echo "$filelist";
echo "${#filelist[@]}"
Run Code Online (Sandbox Code Playgroud)

我的数组包含许多元素,但最后一个命令表明我的数组只包含一个元素.我究竟做错了什么?

evi*_*tto 8

您需要使用括号让bash将其识别为数组.

filelist=($(find $name -type f | sort))
echo ${#filelist[@]}
Run Code Online (Sandbox Code Playgroud)