How to test for if two files exist?

前端 未结 4 1978
耶瑟儿~
耶瑟儿~ 2021-02-02 07:11

I would like to check if both files exist, but I am getting

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

Can anyone see what\'s wrong?

#!/b         


        
4条回答
  •  醉酒成梦
    2021-02-02 07:34

    [ -f .ssh/id_rsa -a -f .ssh/id_rsa.pub ] && echo both || echo not
    

    or

    [[ -f .ssh/id_rsa && -f .ssh/id_rsa.pub ]] && echo both || echo not
    

    also, if you for the [[ ]] solution, you'll probably want to change #!/bin/sh to #!/bin/bash in compliance with your question's tag.

提交回复
热议问题