如何在Shell脚本中从循环中排除某些文件 [英] How to exclude some files from the loop in shell script

查看:127
本文介绍了如何在Shell脚本中从循环中排除某些文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#! /bin/sh
for file in $Files/*.txt; do
    chmod 777 $file
done

它将为所有 .txt 文件赋予 777 权限,但是我还有其他7个我不想为其提供的 .txt 文件给予777许可.我怎样才能做到这一点?

It will give permission 777 to all .txt files but I've 7 other .txt file for which I don't want to give 777 permission. How can I do that?

推荐答案

您可以添加如下条件检查.由于没有明确的属性来区分要排除的文件,因此需要专门检查每个名称:

you can add a conditional check as below. As there's no clear attribute differentiating the files you want to exclude, you'd need to specifically check for each name :

for file in $Files/*.txt
do 
    if [ "$file" = abra.txt -o "$file" = aura.txt -o "$file" = cab.txt -o "$file" = college.txt -o "$file" = jamla.txt -o "$file" = kalut.txt -o "$file" = school.txt  ]
    then 
       continue 
    fi 
    chmod 777 "$file"
done

这篇关于如何在Shell脚本中从循环中排除某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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