我需要编写一个基本程序,它会在用户指定的目录中找到以字节为单位的奇数(不均匀)大小的文件,然后重命名它们。我写了一个代码,但无法弄清楚它有什么问题,因为我才刚刚开始编写 bash 脚本......我的目录中有 3 个文件,这是我为它们得到的错误:
./Untitled: line 18: AppIcon.icns: command not found
mv: cannot stat ‘AppIcon.icns’: No such file or directory
./Untitled: line 18: AssociatedVm.txt: command not found
mv: cannot stat ‘AssociatedVm.txt’: No such file or directory
./Untitled: line 18: Info.plist: command not found
mv: cannot stat ‘Info.plist’: No such file or directory
我的脚本代码:
#!/bin/bash
n=0
echo “Specify directory”
read directory
if [ -d $directory ]; then
echo “Directory found”
else
echo “Directory not found”
exit 0
fi
for file in $( ls $directory );
do
fsize=$(stat "$directory/$file" -c %s)
if [ $((fsize%2))=1 ]; then
mv "$directory/$file" "$directory/$file.odd"
n=$((n + 1))
fi
done
echo ”Number of renamed files: $n ”