Bash 中的时间比较不起作用并抛出语法错误

Bash 中的时间比较不起作用并抛出语法错误
#Run if time is between these two times
hour_first="19:59"
hour_last="22:01"
array_hosts=( "192.168.2.254;VPN one" "192.168.21.3;another vpn name" )
last_reset=""

reset_vpns(){
  current_time=$(date +%H:%M) # format :   HH:MM  with lead 0 if less than 10
  current_day=$(date +%j)
  echo $current_time
  echo $current_day
  
    if ! [[ "$current_day" -eq "$last_reset" ]]; then
        # if the current time is between the allow timeframe for resets
    if [[ "$current_time" > "$hour_first" ]] && [[ "$hour_last" > "$current_time" ]];then
        for element in "${array_hosts[@]}";do
        vpnname=$(echo "$element" | awk -F";" '{print $2}')
        echo "Daily Reset VPN: $vpnname "
        /usr/local/bin/php /usr/local/bin/pfsense-vpnreset.php "$vpnname"
      done
      echo $current_day > $log_file
    fi
  fi
}

reset_vpns

我上面的代码检查是否需要每天重置我的VPN。

但是,当我运行它时,该行出现以下语法错误:

        if [[ "$current_time" > "$hour_first" ]] && [[ "$hour_last" > "$current_time" ]];then

错误:

main.sh: line 14: conditional binary operator expected
main.sh: line 14: syntax error near `"$hour_first"'
main.sh: line 14: `    if [[ "$current_time"  "$hour_first" ]]  [[ "$hour_last"  "$current_time" ]];then'

另外,我可以把第二个 else 放在哪里if

我究竟做错了什么?

相关内容