./shell.sh: 行6: [: =~: 二項演算子が必要

./shell.sh: 行6: [: =~: 二項演算子が必要

出力が特定の部分文字列と等しくないまで、無限ループでコマンドを実行し続ける次のシェルスクリプトを実行しようとしています。

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

おすすめ記事