庆典〜for循环在特定目录中的文件 [英] bash ~ for loop over specific files in a directory

查看:106
本文介绍了庆典〜for循环在特定目录中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个目录中,您有一些不同的文件 - .TXT .SH ,然后计划文件没有包含.foo 修改

如果您 LS 的目录:

  blah.txt
blah.sh
胡说
无聊症

我如何知道一个for循环仅使用文件没有包含.foo 修改?因此,对文件等等和无聊症在上面的例子做的东西。

的基本语法是:

 #!/斌/庆典
FILES = /家庭/ SHEP /桌面/测试/ *在$ FILES˚F

    XYZ功能
DONE

正如你可以看到这有效地遍历目录中的所有内容。我怎样才能排除 .SH .TXT 或其他任何修改?

我一直在玩一些if语句,但我真的很好奇,如果我能为那些不修改的文件中进行选择。

也可能有人告诉我这些纯文本文件正确的行话不.TXT?


解决方案

 #!/斌/庆典
FILES = /家庭/ SHEP /桌面/测试/ *在$ FILES˚F

如果[$ F!= * \\ *。]
然后
  做东西
科幻
DONE

In a directory you have some various files - .txt, .sh and then plan files without a .foo modifier.

If you ls the directory:

blah.txt
blah.sh
blah
blahs

How do I tell a for-loop to only use files without a .foo modify? So "do stuff" on files blah and blahs in the above example.

The basic syntax is:

#!/bin/bash
FILES=/home/shep/Desktop/test/*

for f in $FILES
do
    XYZ functions
done

As you can see this effectively loops over everything in the directory. How can I exclude the .sh, .txt or any other modifier?

I have been playing with some if statements but I am really curious if I can select for those non modified files.

Also could someone tell me the proper jargon for these plain text files without .txt?

解决方案

#!/bin/bash
FILES=/home/shep/Desktop/test/*

for f in $FILES
do
if [[ "$f" != *\.* ]]
then
  DO STUFF
fi
done

这篇关于庆典〜for循环在特定目录中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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