Execute multiple adb shell command in bash script

Viewed 14

I am building a bash script for recursively copy files from the Android data folder using adb shell command. The code is like

touch2() { mkdir -p "$(dirname "$1")" && touch "$1" ; }

PHONE_ADDR="192.168.0.105"
PHONE_PORT="5555"

adb connect ${PHONE_ADDR}:${PHONE_PORT}
adb shell "run-as com.company.package find ./databases -type f" > temp.txt

input="temp.txt"
while IFS= read -r line
do
  echo $line
  touch2 $line
  adb shell "run-as com.company.package cat $line" > $line
#   BACK_PID=$!
#   wait $BACK_PID
done < $input

adb disconnect ${PHONE_ADDR}:${PHONE_PORT}

Basically I first list all files' path in Android data folder and storage them in temp.txt. Then I would like to read trough temp.txt line by line and process each file with an adb shell command.

But it only processes the first line of file in temp.txt. I am thinking of if the while loop is not waiting for the adb shell command to finish. So I have tried to add a wait command but it does not work.

0 Answers
Related