0
我是新的shell腳本,並試圖讓所有的android設備在一個數組,但我的數組是空的,當功能完成。殼 - 獲取Android設備到陣列
#!/bin/bash
declare -a arr
let i=0
MyMethod(){
adb devices | while read line #get devices list
do
if [ ! "$line" == "" ] && [ `echo $line | awk '{print $2}'` == "device" ]
then
device=`echo $line | awk '{print $1}'`
echo "Add $device"
arr[$i]="$device"
let i=$i+1
fi
done
echo "In MyMethod: ${arr[*]}"
}
################# The main loop of the function call #################
MyMethod
echo "Not in themethod: ${arr[*]}"
arr
- 是空的,我做錯了什麼?
感謝您的諮詢。
太棒了!非常感謝。 – AlexMrKlim