The following switch statement has strange behavior:
3)
if [ $state -ne $last_state ]
then
echo "state: $state"
fi
stty -F $SERIAL $BAUD -echo igncr
echo "befor cat"
{
cat -v $SERIAL >> $USBDRIVE/gpsData_$filecounter.txt && echo "after cat"
} || {
echo "catch"
state=0
last_state=3
((filecounter++))
}
;;
I thought, that when the cat command fails while is beeing excecuted, "after cat" will be written and than the part after || will be excecuted. But when I look at the output, it seems that after echoing "after cat" a break happen so that the actual state does not change and will be entered one more time. Then stty fails, too (becaus the serial adapter is missing). After that, the cat command againt fails at the beginning but now enters the "catch" block....
Here is the relevant output:
pi@rpi ~/serial_logger $ ./serial_logger.sh
serial adapter found: ttyUSB0
state: 1
USB-Storage found: usb0
state: 3
before cat
after cat #here should be entered state 0
state: 3
stty: /dev/ttyUSB0: No such file or directory
before cat
cat: /dev/ttyUSB0: No such file or directory
catch
state: 0
USB-Storage found: usb0
state: 2
What am I doing wrong?