如何在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