Bash 不使用`ls`列出文件
示例
使用Bashshell的文件名扩展和大括号扩展功能来获取文件名:
# 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
热门推荐
10 感恩父亲贺卡祝福语简短
11 舞台上祝福语大全简短
12 2026年祝福语大全简短
13 校庆结尾文案祝福语简短
14 祝朋友祝福语简短好看
15 撩妹生日祝福语简短
16 美国护士毕业祝福语简短
17 送你妹妹新婚祝福语简短
18 长辈生日横幅祝福语简短