I’m trying to write a simple little script to query a 3g connection, and if the connection has dropped, instigate a reconnection.
My problem is in checking the output of the command – two seemingly equal strings are not evaluated as equal. I’m sure there’s a noob error in here somewhere!
#!/bin/bash
echo "Checking connection"
a="Not connected."
b=$(./sakis3g status --console)
if [[ "$a"!="$b" ]]; then
echo "Strings not equal:"
echo "$a"
echo "$b"
else
echo "Strings equal!!"
fi
The output when run:
user@mypc:~$ ./test_3g.sh
Checking connection
Strings not equal:
Not connected.
Not connected.
When running ./test_3g.sh | cat -A:
user@mypc:~$ ./test_3g.sh | cat -A
Checking connection$
Strings not equal:$
Not connected.$
Not connected.$
You have to put spaces around operators:
Without spaces you end up with a single string, equivalent to
"$a!=$b". And testing just a string returns true if that string is non-empty…