shell – 循环遍历给定目录中的所有文件

参见英文答案 > Shellscript Looping Through All Files in a Folder6个
这是我正在尝试做的事情:

为shell脚本提供一个参数,该脚本将在jpg,bmp,tif扩展名的所有文件上运行任务.

例如:./ doProcess / media / repo / user1 / dir5

并且该目录中的所有jpg,tif文件都将运行某个任务.

我现在拥有的是:

for f in *
do
  imagejob "$f"  "output/${f%.output}" ;
done

我需要帮助for循环来限制文件类型,并且还有一些在指定目录而不是当前目录下启动的方法.

使用shell扩展而不是ls
for file in *.{jpg,tif}
do
  imagejob "$file" "output/${file%.output}"
done

如果你有bash 4.0,你可以使用globstar

shopt -s globstar
shopt -s nullglob
shopt -s nocaseglob
for file in **/*.{jpg,tif}
do
  # do something with $file
done

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...