linux - 如何测试是否存在两个文件?

我想检查这两个文件是否存在,但我得到了

test.sh: line 3: [: missing `]'

谁能看出问题所在?

#!/bin/sh

if [ -f .ssh/id_rsa && -f .ssh/id_rsa.pub ]; then
   echo "both exist"
else
   echo "one or more is missing"
fi

最佳答案

尝试添加一个额外的方括号。

if [[ -f .ssh/id_rsa && -f .ssh/id_rsa.pub ]]; then

https://stackoverflow.com/questions/8971012/

相关文章:

linux - 在 bash 脚本中使用 curl 并获取 curl : (3) Illegal c

python - 如何从 subprocess.Popen() 获取输出。 proc.stdout.

linux - shell 脚本 : Run function from script over s

c++ - 在 64 位 Linux 操作系统上编译 32 位程序导致 fatal error

linux - 是否可以使用 shell 脚本递归地创建文件夹?

linux - 导出在我的 shell 脚本中不起作用

linux - Hadoop:«错误:未设置 JAVA_HOME»

c++ - 在 Linux 中显式导出共享库函数

linux - 为什么使用 dd 克隆磁盘时使用 conv=notrunc?

linux - 仅当变量包含特定字符串时才运行 Ansible 任务