当我rm *.old.*在命令行上执行它时,它会正确删除,但是当我在脚本的以下部分执行它时,它并没有 rm 所有*.old.*文件。
我的 bash 脚本有什么问题:
for i in ./*; do
if [[ -f $i ]]; then
if [[ $i == *.old.* ]]; then
oldfile=$i
echo "this file is to be removed: $oldfile"
rm $oldfile
exec 2>errorfile
if [ -s $errorfile ]
then
echo "rm failed"
else
echo "removed $oldfile!"
fi
else
echo "file with old extension does not exist"
fi
orig=$i
dest=$i.old
cp $orig $dest
echo "Copied $i"
else
echo "${i} is not a …Run Code Online (Sandbox Code Playgroud) 运行以下脚本时出现以下错误:
cp: cannot stat ls
Run Code Online (Sandbox Code Playgroud)
脚本内容
#!/bin/bash
#make copies of all files in directory
cd /home/don
LIST='ls'
for i in $LIST; do
ORIG=$i
DEST=$i.old
cp $ORIG $DEST
echo "Copied $i"
done
Run Code Online (Sandbox Code Playgroud)
有人可以看到问题吗?