我正在尝试从stdin读取文件列表,每个文件由换行符分隔,但我注意到只有第一个元素被添加到列表中。我通过输入两个字符串然后按q来发现了这一点。有人能解释一下为什么吗?
files=()
read input
while [ "$input" != "q" ] ;
do
files+=( "$input" )
read input
done
for f in $files ;
do
echo "the list of files is:"
echo "$f"
echo "The length of files is ${#files} " #prints 1, even if 2+ are entered
done
${#files[@]}
。 - glenn jackman