How to giv two conditions in IF statement..??

Actually i need to satisfy both the condition..
lik i'm lookin for two different files.. and if BOTH the files r not present then it should run the followin script.. For example

inputfile1=data/in/inputfile1.txt
inputfile2=data/in/inputfile2.txt

if [ ! -f ${inputfile1} && ! -f ${inputfile2} ]
then

echo " "
echo "ERROR: Files not found."
echo " "
exit 1

fi

echo " "
echo "RUN SUCCESSFUL: Both Files found. "
echo " "

exit 1

Here even if the second file is not present its showing RUN SUCCESSFUL.. Please Help...

Replace && by -a

inputfile1=data/in/inputfile1.txt
inputfile2=data/in/inputfile2.txt

if [  ! -f ${inputfile1} -a ! -f ${inputfile2} ]
then
   echo " "
   echo "ERROR: Both files not found."
   echo " "
   exit 1
fi

if [  ! -f ${inputfile1} -o ! -f ${inputfile2} ]
then
   echo " "
   echo "ERROR: File(s) not found."
   echo " "
   exit 1
fi

echo " "
echo "RUN SUCCESSFUL: Both Files found. "
echo " "

exit 0

jean-Pierre.

Just shorter..

#!/bin/sh
inputfile1=data/in/inputfile1.txt
inputfile2=data/in/inputfile2.txt
[ -f ${inputfile1} -a -f ${inputfile2} ] && echo OK || echo NOK

Simple Mistake :slight_smile:
You can use && if u use like

in your code

Simple Mistake :slight_smile:
You can use && if u use like

in your code

sorry didnt see the replies

shorter form :

inputfile1=data/in/inputfile1.txt
inputfile2=data/in/inputfile2.txt

[ ! -f ${inputfile1} -a ! -f ${inputfile2} ] && { echo "\n ERROR: Both files not found. \n" ; exit 1 ;}

[ ! -f ${inputfile1} -o ! -f ${inputfile2} ] && { echo "\n ERROR: File(s) not found. \n" ; exit 1 ;}

echo "\n RUN SUCCESSFUL: Both Files found. \n"
exit 1