如何在sh?
中创建不等于的语句if [ "$db_name" != `mysql -uroot -p${db_pass} -s -N -e "SELECT schema_name FROM information_schema.schemata WHERE schema_name='${db_name}'"` ]; then
echo "not found"
fi
test.sh: 6: [: !=: argument expected
答案 0 :(得分:1)
引用[ and ]
中的参数:
if [ "$db_name" != "`mysql -uroot -p${db_pass} -s -N -e "SELECT schema_name FROM information_schema.schemata WHERE schema_name='${db_name}'"`" ]; then echo "fundet"
echo "not found"
fi
如果mysql命令返回空字符串,或者如果输出带空格,那么你将得到没有引号的错误。