执行pg的shell脚本,报错
./pg_ms_status.sh: line 17: [: ==: unary operator expected
if [ $db_role == f ];then echo -e `date +"%F %T"` "pg master db is ok" >> $LOGFILE
报错的原因是:如果变量 db_role 的值为空,那么就if语句就变成了if [ = "f" ],这不是一个合法的条件。
为了避免出现这种情况,我们必须给变量加上引号if [ "$db_role" = "f" ],这样即使是空变量也提供了合法的测试条件,,if [ " " = "f" ]