Created
December 11, 2012 04:48
-
-
Save myamamic/4255943 to your computer and use it in GitHub Desktop.
[Android][script] 接続している端末のうち、任意の1台のシリアル番号を取得する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# このスクリプトは他のスクリプトから使われます | |
# | |
# 接続するデバイスのシリアル番号を取得するスクリプト | |
# このスクリプトの標準出力の最後に、選択したデバイスのシリアル番号が出力されます | |
# 使う側は、最後の出力を使ってください | |
BUFIFS=$IFS | |
IFS= | |
# 少なくとも1台端末が接続されるまで待つ | |
adb wait-for-device 1>&/dev/null | |
i=0 | |
CONNECTED_DEVICE_ID= | |
DEVICE_ID_LIST= | |
while read LINE | |
do | |
# タブで区切られている行の第一フィールドのみ抜き出す. ex) 000000001111<\t>device | |
CONNECTED_DEVICE_ID=`echo ${LINE} | cut -s -f 1` | |
# device IDのみ表示する | |
if [ ${CONNECTED_DEVICE_ID} ]; then | |
echo "${CONNECTED_DEVICE_ID} : [${i}]" | |
i=`expr ${i} + 1` | |
DEVICE_ID_LIST=${DEVICE_ID_LIST}$'\n'${CONNECTED_DEVICE_ID} | |
fi | |
done < <(adb devices) | |
echo "adbを実行するデバイスの番号を入力してください :" | |
read DEVICE_NUMBER | |
i=0 | |
while read LINE | |
do | |
if [ ${LINE} ]; then | |
# 指定されたデバイス番号なら表示し、ファイルに出力する | |
if [ ${i} -eq ${DEVICE_NUMBER} ]; then | |
echo "${LINE}" | |
break | |
fi | |
i=`expr ${i} + 1` | |
fi | |
done < <(echo "${DEVICE_ID_LIST}") | |
IFS=$BUFIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment