代码之家  ›  专栏  ›  技术社区  ›  Rimuru Tempest

这个shell脚本中使用if块的错误是什么?

  •  0
  • Rimuru Tempest  · 技术社区  · 3 月前

    我正在编写一个bash脚本,并编写了一个if子句来检查是否存在多个文件。我使用的子句是-

    if [[ -f /home/step/certs/root_ca.crt && -f /home/step/certs/intermediate_ca.crt && -f /home/step/secrets/root_ca_key && -f /home/step/secrets/intermediate_ca_key && -f /home/step/config/ca.json && -f /home/step/config/defaults.json]]; then
        echo 'Existing Certificate Authority found!\nUsing the existing certificate authority...'
    

    它给出了这个错误-

    syntax error in conditional expression: unexpected token `;'
    

    我试着移除 ; 并得到另一个语法错误- syntax error in conditional expression

    检查是否存在多个文件的正确语法是什么?

    1 回复  |  直到 3 月前
        1
  •  0
  •   Antonio Petricca    3 月前

    错误位于 /home/step/config/defaults.json]]; .

    你必须重写为 /home/step/config/defaults.json ]]; 。您错过了前面的必填空格 ]] .