The variable I wish to extract will look something like this
ttyACM0
ttyACM1
I would like to iterate over this variable and issue the command:
echo disconnect > /dev/ttyACM0
and then
echo disconnect > /dev/ttyACM1
My current code that isn't working looks like:
MCCI=`ls /dev | grep "ttyACM[0-9]" | grep -v "$all_dongles"`
while IFS= read -r line
do
echo disconnect > /dev/"$line"
sleep 1
echo disconnect > /dev/"$line"
sleep 1
echo disconnect > /dev/"$line"
done <<< "$MCCI"
The code is currently overwriting ttyACM0 which is obviously not what I want. I'm issuing the same disconnect code 3 times because it was advised to do so, after the disconnect loop I must issue a connect code as well, which is identical to the above code. This entire code is executed over SSH
UPDATE I am connecting to a machine via ssh and I am trying to verify the serial number of a dongle that I prompt the user for. I need to disconnect unnecessary dongles that do not match the serial number provided by the user. In order to do this I must verify which MCCI corresponds to which dongle. All dongles and MCCI are /dev/ttyACM[0-9] My thinking was to disconnect all MCCIs (For which I know the numbers of thanks to the MCCI variable) and then turn them back on one at a time, check which dongle is now connected, grep the dongle serial number and concatenate it to the corresponding MCCI ttyACM#, and add that to an array, disconnect again I then plan to iterate over that array and search for the serial number, remove the relevant ttyACM# and connect the dongle
I have 3 variables Dongles & MCCI - ls /dev | grep "ttyACM[0-9]"
Dongles - a similar variable that returns information about the dongles like serial number and ttyACM[0-9]
and the MCCI which is just excluding the known dongles from the Dongles & MCCI variable
MCCI=
is .. not great, you might want to read https://unix.stackexchange.com/questions/128985/why-not-parse-ls-and-what-to-do-instead – Marcus Müller Nov 08 '22 at 15:58$all_dongles
? – Kusalananda Nov 08 '22 at 16:05grep -v "$all_dongles"
makes no sense. – Marcus Müller Nov 08 '22 at 16:24ls /dev/tty*
) and which devices you want to include and which devices you want to exclude. – terdon Nov 08 '22 at 18:00