用for循环编写删除文件的shell脚本

1:bash环境。
2:在home目录下手动创建文件1,编写脚本2.sh,执行此脚本可删除文件1。
3:可用命令:find rm 等。
4:使用for循环。

求大神,小弟菜鸟一个,希望能简单点~~~~

#!/bin/bash
#2.sh
cd #进入加目录
touch 1 #创建文件1
read -p "请输入要删除的文件 1 :" file
if [ "$file" != "1" ];then
echo "请输入1 不许输入别的。谢谢!"
fi
for i in $file ;do #用for循环把$file代入$i
rm -rf $i #删除$i
echo "$i 被删除了。"
done #结束
温馨提示:内容为网友见解,仅供参考
第1个回答  2012-06-14
vim removefile.sh

#!/bin/sh
# remove files with name pattern matching regexp
echo -n "Enter directory: "; read dir
echo -n "Enter pattern: "; read pat
for loop in `find $dir -name "*$pat*"`
do
rm $loop && echo "$loop has been removed!"
done
相似回答