klm123
klm123

Reputation: 12865

Check whether two files exist (in shell script)

I'm writing a shell script and trying to check whether two files exists. Here is the script example:

#!/bin/bash

if [[ [ -e File1Name ] -a [ -e File2Name ] ]]
then
  echo Yes
el
  echo No
fi

and get

script: line 5: conditional binary operator expected
script: line 5: syntax error near `-e'
script: line 5: `if [[ [ -e CA ] -a [ -e CA-draw ] ]]'

What is wrong with my script and hot to fix it?

Upvotes: 2

Views: 7124

Answers (2)

Stephane Rouberol
Stephane Rouberol

Reputation: 4384

if [ -e File1Name -a -e File2Name ]
then
    echo Yes
else
    echo No
fi

Upvotes: 3

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798686

Both [[ and [ are commands; you need to pick one of them, and use only it with if.

Upvotes: 1

Related Questions