1

I am trying to look for 2 files in a directory and if both of them are present, I need to echo "Bravo" else "You lost" but I am getting stuck here. If the 1st file is present and 2nd is not, I am getting "You lost" BUT if 1st file is absent and 2nd file is present I am getting "Bravo". Below is my code. Someone please help me.

 find /var/tmp/crontab -name crontest|grep crontest
 if [ "$?" eq 0 ]; then
     find /var/tmp/crontab -name cronjob|grep cronjob
     if [ "$?" -eq 0 ]; then        
         echo "Bravo"
     else
         echo "You lost"
     fi
 fi

2 Answers 2

2

No need for find, grep, et al - you can do it a lot more simply just with bash built-ins, e.g.

if [ -e /var/tmp/crontab/crontest ] && [ -e /var/tmp/crontab/cronjob ] ; then 
    echo "Bravo"
else
    echo "You lost"
fi
Sign up to request clarification or add additional context in comments.

Comments

0

You can use a one liner for this.

[ -f /var/tmp/crontab/crontest -a -f /var/tmp/crontab/crontest2 ] &&  \ 
echo "bravo" || echo "lost"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.