Creating a script which compares the return value from an AT command
0
votes
0
answers
83
views
I am trying to write a shell script that can save the output of a piped process to a variable. This variable is then compared to a known string in order to discern whether or not my AT modem is connected to a network or not. My problem is when I run my script, the variable never matches the comparator no matter what I do. Minimal example attached. I ran my script in bash -x mode so I could track the variables along the script.
connected=$(echo -e 'AT+CREG?\r' > /dev/ttyUSB2 | head -2 /dev/ttyUSB2)
echo "\n"
compare=" $\'\r\' +CREG: $\'0,1\r"
echo "\n"
echo ${connected}
echo "\n"
if [ ${connected} = "${compare}" ] ; then
echo "This may not be an AT&T card"
else
echo "Missed the if statement"
fi
Asked by adamsthename
(1 rep)
Nov 15, 2022, 09:33 PM
Last activity: Nov 15, 2022, 09:34 PM
Last activity: Nov 15, 2022, 09:34 PM