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

问题描述 投票:0回答:1

我正在编写一个 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

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

linux bash shell
1个回答
0
投票

错误位于

/home/step/config/defaults.json]];

你必须将其重写为

 /home/step/config/defaults.json ]];
。您错过了
]]
之前的必填空格。

© www.soinside.com 2019 - 2024. All rights reserved.