./shell.sh: 第 6 行: [: =~: 需要二元运算符

./shell.sh: 第 6 行: [: =~: 需要二元运算符

我正在尝试执行以下 shell 脚本,其中我试图在无限循环中继续执行命令,直到输出不等于某个子字符串

checkDeviceStatus=$(adb shell getprop sys.boot_completed 2>&1)

function Check_Status () {

while [ ! "$checkDeviceStatus" =~ "device offline" ] || [ ! "$checkDeviceStatus" =~ "device still authorizing" ]
  do
  if [ ! "$checkDeviceStatus" =~ "device offline" ] || [ ! "$checkDeviceStatus" =~ "device still authorizing" ];
       then
          echo "Device is now up and running!!: '$checkDeviceStatus'"
          break
       else 
            echo "'$checkDeviceStatus'"
       fi;
done

};

Check_Status

但我收到以下错误

./shell.sh: line 6: [: =~: binary operator expected
./shell.sh: line 8: [: =~: binary operator expected

答案1

#!/bin/bash

function Check_Status () {

while [[ "$(adb shell getprop sys.boot_completed 2>&1)" =~ "device offline" ]] || [[ "$(adb shell getprop sys.boot_completed 2>&1)" =~ "device still authorizing" ]] || [[  "$(adb shell getprop sys.boot_completed 2>&1)" =~ "no devices/emulators found" ]];
  do
  sleep 1
  if [[ "$(adb shell getprop sys.boot_completed 2>&1)" == "" ]] || [[ "$(adb shell getprop sys.boot_completed 2>&1)" == 1 ]];
  then 
     echo "Device is now up and running!!: '$(adb shell getprop sys.boot_completed 2>&1)'"
     break      
  else 
     echo "'$(adb shell getprop sys.boot_completed 2>&1)':("
  fi    
done

};

Check_Status

相关内容