Skip to content

Instantly share code, notes, and snippets.

@Caleb9
Created April 28, 2019 09:52
Show Gist options
  • Save Caleb9/e018b8653614363e24cb0a90c155d449 to your computer and use it in GitHub Desktop.
Save Caleb9/e018b8653614363e24cb0a90c155d449 to your computer and use it in GitHub Desktop.
Simple bash script to select and run specific AVD device.
#!/bin/bash
# Run `emulator` to obtain devices (assumes emulator is on the PATH)
list_avds=$(emulator -list-avds)
# Split list_avds by newline and save to avds array
readarray -t avds <<<$list_avds
# Check if zero or one device only
devices_count=${#avds[@]}
if [ $devices_count -eq 0 ]
then
echo No devices found. Create a device using avdmanager.
exit
elif [ $devices_count -eq 1 ]
then
# Run emulator with the only device
echo Only one device found. Starting ${avds[0]}.
exec emulator -avd ${avds[0]}
fi
# Output available devices with indexes
echo Available devices:
index=1
for avd in ${avds[@]}
do
echo $index: $avd
index=$((++index))
done
echo -n "Number of the device to start: "
# Read user input
read selection
# Select entry in avds array
avd=${avds[$((--selection))]}
# Run `emulator`
emulator -avd $avd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment