我试图编写一个简单的脚本来查询3g连接,如果连接断开,则启动重新连接。
我的问题在于检查命令的输出 - 两个看似相等的字符串不能被评估为相等。我相信这里一定有一个新手错误!
#!/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
运行时的输出:
user@mypc:~$ ./test_3g.sh
Checking connection
Strings not equal:
Not connected.
Not connected.
当运行
./test_3g.sh | cat -A
时:user@mypc:~$ ./test_3g.sh | cat -A
Checking connection$
Strings not equal:$
Not connected.$
Not connected.$
./test_3g.sh | cat -A
命令。如果你的cat
不支持-A
选项,尝试使用./test_3g.sh | cat -v
命令。 - Keith Thompson