BASH版本4.3.30(1)-发行版(x86_64-pc-linux-gnu)中断了在版本4.2.53(1)-发行版(x86_64-redhat-linux-gnu)上工作的脚本
此脚本适用于Fedora 20:BASH版本4.3.30(1)-发行版(x86_64-pc-linux-gnu)中断了在版本4.2.53(1)-发行版(x86_64-redhat-linux-gnu)上工作的脚本,linux,bash,Linux,Bash,此脚本适用于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
#!/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)发布版(x86_64-pc-linux-gnu)上失败并出现错误
它失败并抱怨:
x++:未找到
x%n:找不到
在以后的版本中对BASH变量做了哪些更改以中断功能?是否
((x+=1))
和((x%n==0))
起作用?有时空格很重要。语法很好。是否您的bash
软链接到您的shell
?也就是说,您可以检查它是否在bash下而不是在shell中运行吗?或者您可能正在使用sh
命令调用脚本,而不是仅仅运行它。您好,谢谢您的评论。间距计算不起作用。已修复;我从命令行中删除了sh,而且下载的文件不可执行。更改了权限,它工作了。我已经从谷歌硬盘下载,以确保它的工作。谢谢你的帮助!