bash – [:-eq:一元运算符预期

前端之家收集整理的这篇文章主要介绍了bash – [:-eq:一元运算符预期前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. #!/bin/bash
  2. export PROCNAME=test
  3. export TABLE_ID=0
  4.  
  5. if [ ${TABLE_ID} -eq "" ]; then
  6. echo hello
  7. fi

以上抛出错误

[: -eq: unary operator expected

如何使用双方括号[[${TABLE_ID} -eq“”]]来解决这个问题.

用=测试字符串相等性.
  1. #!/bin/bash
  2. export PROCNAME=test
  3. export TABLE_ID=0
  4.  
  5. if [ "${TABLE_ID}" = "" ]; then
  6. echo hello
  7. fi

猜你在找的Bash相关文章