私はシェルスクリプトを初めて使用し、配列内のすべての 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
- は空です。何が間違っていますか?
アドバイスをありがとう。