我正在创建一个自定义脚本来使用Clonezilla运行备份。该脚本按预期工作(到目前为止),但我对变量赋值有点麻烦。
变量赋值行(maxBackups = 4)在当前目录中创建一个名为“4”的文件,if测试无法正常工作。
(我理解它的方式,父目录的链接计为具有此目录计数方法的目录。)
我做错了什么?我知道这很简单...
由于
#!/bin/bash
# Automated usb backup script for Clonezilla
# by DRC
# Begin script
# Store date and time for use in folder name
# to a variable called folderName
folderName=$(date +"%Y-%m-%d--%H-%M")
# mount second partition of USB media for storing
# saved image
mount /dev/sdb2 /home/partimag/
# Determine if there are more than 3 directories
# and terminate the script if there are
cd /home/partimag
maxBackups=4
numberOfBackups=$(find -maxdepth 1 -type d | wc -l)
if [ $numberOfBackups > $maxBackups ]; then
echo "The maximum number of backups has been reached."
echo "Plese burn the backups to DVD and remove them"
echo "from the USB key."
echo "Press ENTER to continue and select 'Poweroff'"
echo "from the next menu."
# Wait for the user to press the enter key
read
# If there are three or less backups, a new backup will be made
else
/usr/sbin/ocs-sr -q2 -c -j2 -a -z0 -i 2000 -sc -p true savedisk $folderName sda
fi
答案 0 :(得分:0)
maxBackups=4
未在您的目录中创建名为4
的文件。创建该文件的是if [ $numberOfBackups > $maxBackups ]
位。 >
重定向到输出文件,因为[
是命令,而不是关键字。您可以尝试其中之一:
if [ $numberOfBackups -gt $maxBackups ] # -gt is test's version of greater than
if [[ $numberOfBackups > $maxBackups ]] # double brackets are keywords, not commands
if (( numberOfBackups > maxBackups )) # arithmetic context doesn't even require $