Linux – How to test for if two files exist

bashlinux

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

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

Can anyone see what's wrong?

#!/bin/sh

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

Best Solution

Try adding an additional square bracket.

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