Bash 不使用`ls`列出文件

示例

使用Bash shell的文件名扩展和大括号扩展功能来获取文件名:

# display the files and directories that are in the current directory
printf "%s\n" *

# display only the directories in the current directory
printf "%s\n" */

# display only (some) image files
printf "%s\n" *.{gif,jpg,png}

要将文件列表捕获到变量中进行处理,通常最好使用bash数组:

files=( * )

# iterate over them
for file in "${files[@]}"; do
    echo "$file"
done