The Android device selection list is displayed, and the Shell script of the specified Android device Console is displayed.
If a PC is connected to multiple Android devices (including Android simulators), you must use adb-s deviceid shell when entering the Console. This article has compiled a Shell script file (which can be used in Linux or OS X, and bat or cmd in windows ).
First, use the adb devices command to scan how many Android devices are connected to the PC. Then, extract the device name from the returned value and display a menu. Finally, you can select the serial number before the menu item to enter the specified Android device. You do not need to enter the deviceid.
Shows the effect.
Common. sh
Selected_device = "" # "": no available Android device function find_devices () {device_list = $ (adb devices) if ["$ {device_list: 0: 4 }"! = "List"]; then device_list = $ (adb devices) if ["$ {device_list: 0: 4 }"! = "List"]; then exit fi value = $ (echo $ device_list | cut-d ''-f5) if [" $ value "=" "]; then echo "no available Android device" else selected_device = $ value # assume that only one device has value =$ (echo $ device_list | cut-d'-f7) # multiple devices if ["$ value "! = ""]; Then I = 5 index = 1 value = "~~~ "Echo" list of available devices "while [" "=" "] do value = $ (echo $ device_list | cut-d'-f $ I) let "I = $ I + 2" if ["$ value" = ""]; then break; fi echo "$ index: $ value "let" index = $ index + 1 "done read-p" which Android device do you want to choose? Enter the serial number (1): "number if [" $ number "=" "]; then number = 1 fi let "number = 3 + $ number * 2" selected_device = $ (echo $ device_list | cut-d ''-f $ number) # retrieve the device ID fi Based on the device index selected by the user}
Shell. sh
source common.shfind_devicesif [ "$selected_device" != "" ]; then adb -s $selected_device shell $1fi
You need to put the common. sh and shell. sh files in the same directory, and then execute shell. sh (you need to use the chmod command to set the executable permissions)
This script is provided by "Android Deep Exploration Volume 1: HAL and driver development.