Variables 变量分配在当前目录中创建文件,不分配变量

Variables 变量分配在当前目录中创建文件,不分配变量,variables,clonezilla,Variables,Clonezilla,我正在创建一个自定义脚本来使用Clonezilla运行备份。脚本按预期工作(到目前为止),但变量赋值有点问题 变量赋值行(maxBackups=4)在当前目录中创建一个名为“4”的文件,并且if测试无法正常工作 (按照我的理解,使用此目录计数方法,指向父目录的链接算作一个目录。) 我做错了什么?我知道这很简单 谢谢 #!/bin/bash # Automated usb backup script for Clonezilla # by DRC # Begin script # Stor

我正在创建一个自定义脚本来使用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

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 $

非常感谢你,这很有魅力!试图投票支持你,但没有足够的代表性。。。