我想要用这个脚本将当前目录的文件放入一个数组中,并打印出每个文件:
#!/bin/bash
files=(*)
for file in $files
do
echo $file
done
# This demonstrates that the array in fact has more values from (*)
echo ${files[0]} ${files[1]}
输出:
echo.sh
echo.sh read_output.sh
有人知道为什么在这个for循环中只打印出第一个元素吗?