Created
May 1, 2014 16:14
-
-
Save royclarkson/f39115fe0a7ac1f08630 to your computer and use it in GitHub Desktop.
Bash script to kill all running Android emulators
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 | |
for ((PORT=5554; PORT<=5584; PORT+=2)); do | |
echo killing emulator-$PORT... | |
adb -s emulator-$PORT emu kill | |
done |
Nowadays we can retrieve a list of all emulators with corresponding ports and kill emulators that actually exists
adb devices | grep "emulator-" | while read -r line ; do
suffix=" device"
emulatorInstanceName=${line%${suffix}}
echo "Killing $emulatorInstanceName"
adb -s ${emulatorInstanceName} emu kill
done
This gist was super helpful to me in some CI scripting. Wanted to point out for future spelunkers that the loop above can use the ability of read
to assign multiple variables to eliminate the munging of emulatorInstanceName
like so:
adb devices | grep "emulator-" | while read -r emulator device; do
adb -s $emulator emu kill
done
Another take:
#!/bin/bash
devices=`adb devices`
for device in $devices; do
if [[ "$device" =~ "emulator-" ]]; then
adb -s $device emu kill
echo $device removed
fi
done
echo "All Done."
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should append " || true" to the kill command so it doesn't return errors for non-running emulators...