此脚本适用于Fedora 20:
#!/bin/bash
# DRE 2015 - Thinking, Realizing, Reacting
# this version reads files of a certain .suffix passed as arg $1
if [ "$1" == "-h" ] ; then
echo "remove_n_file removes files of type (arg1) every nth (arg2) from a directory"
exit
else
:
fi
x=0
y=0
n=$2
echo $n
FILES=./*.$1 # BASH resolves variable for you
for f in $FILES
do
echo $f # iterates through and echoes
((x++)) # postincrements counter for all type file
if ((x%n == 0)) ; then # test for file increment and execute
rm -f "$f" # you need to quote filename variable to get name in proper format to rm command
((y++))
else
:
fi
done
echo files count: "$x"
echo files removed : "$y"
但它在Ubuntu 14.10版本4.3.30(1)-release(x86_64-pc-linux-gnu)
上失败了失败并抱怨:
x ++:找不到 x%n:未找到
在后期版本中对BASH变量进行了哪些更改以打破功能?