Last active
November 21, 2019 21:43
-
-
Save netmaniac/bdd8aa6216d7cc8e04900b2f9c85431d to your computer and use it in GitHub Desktop.
Simple bash function for checking if new usb serial converter has been attached. Tested on Ubuntu 18.04. Use PATH_NAME=$(wait_for_new_usb_serial)
This file contains 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
function wait_for_new_usb_serial() { | |
local array=(`ls -1 //sys/bus/usb-serial/devices/`) | |
local ret="" | |
local current_devices | |
while (true) do | |
sleep 2 | |
current_devices=(`ls -1 //sys/bus/usb-serial/devices/`) | |
for value in "${current_devices[@]}" | |
do | |
if [[ ! " ${array[@]} " =~ " ${value} " ]]; then | |
echo "$value" | |
ret="x" | |
break | |
fi | |
done | |
if [[ ! "x$ret" = "x" ]]; then | |
break | |
fi | |
array=("${current_devices[@]}") | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment