for循环进行多个扩展,并对每个文件执行操作 [英] for loop for multiple extension and do something with each file

查看:167
本文介绍了for循环进行多个扩展,并对每个文件执行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在bash中编写一个for循环,以获取扩展名为jpg,jpeg,png的文件,这是我的尝试,但不起作用

I'm trying to write a for loop in bash to get the files with extension of jpg, jpeg, png, this i my attempt, but does not work

for file in "${arg}"/*.{jpg,jpeg,png}; do echo ${arg}-something.jpg > z.txt ; done;

基本上,我想获取当前文件夹中具有这些扩展名的文件的名称,并对每个文件进行处理,然后以新扩展名的形式输出文件名.

basically, i want to get the name of the file with those extension in the current folder, and do something with each file, then output the filename back with a new extension.

推荐答案

您没有在任何地方使用$file.试试

You are not using $file anywhere. Try

for file in "$arg"/*.{jpg,jpeg,png} ; do
    echo "$file" > z.txt
done

这篇关于for循环进行多个扩展,并对每个文件执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆