Skip to content

Instantly share code, notes, and snippets.

@somq
Created July 26, 2020 15:33
Show Gist options
  • Save somq/c165f351df665edb7948740746e31a3e to your computer and use it in GitHub Desktop.
Save somq/c165f351df665edb7948740746e31a3e to your computer and use it in GitHub Desktop.
ionic5-run-multiple-devices.sh
#!/bin/bash
default_port=8000
deviceLst=$(adb devices | awk 'NR > 1 {print $1}' | sed ':a;N;$!ba;s/\n/ /g')
IFS=' ' read -a array <<< "$deviceLst"
## Clean old background processes
old_processes=$(pgrep -f 'sh -c ionic cordova run')
if [ ! -z "$old_processes" ]; then
echo "Killing old processes $old_processes..."
kill $(pgrep -f 'sh -c ionic cordova run')
else
echo "No old process found."
fi
## Run scripts in background
for i in "${!array[@]}"
do
port=$(($default_port + $i))
echo "Running app on device => ${array[$i]} ($port)"
npm start -- --target="${array[$i]}" --port=$port &
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment