출력이 특정 하위 문자열과 같지 않을 때까지 무한 루프에서 명령을 계속 실행하려고 하는 다음 쉘 스크립트를 실행하려고 합니다.
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