0

Hereby my code:

while [ -f  $load_extract_process ] || [ -f $Sr_details_update_process ]
do
sleep 3s
echo "mango"
done
echo "completed"

I want to check any one of the triggers is present. In that case, go to sleep mode, else print "completed".

1 Answer 1

1

Your example code is missing just one character, a !. You want the loop to continue until one of the file exists, not while it exists. So the following code will work:

while ! [ -f /tmp/a1 ] || [ -f /tmp/a2 ]; do sleep 1; echo sleeping; done

Instead of the shell's ! and ||, you can also use parameters from within test ([ is just an alias for test):

while [ ! -f /tmp/a1 -a ! -f /tmp/a2 ]; do sleep 1; echo sleeping; done

Note how ! is now handled by test ([) not by the shell, and -a means and. You decide which of the two implementations is clearer to you (in my opinion, it's the second).

Sign up to request clarification or add additional context in comments.

2 Comments

your second option worked for me thanks :) while [ -f /tmp/a1 -o -f /tmp/a2 ]; do sleep 1; echo sleeping; done this one worked for me as my requirement thank you very much
I think I misunderstood what exactly you wanted the loop condition to be, but I'm happy you were able to take pieces from my answer to do exactly what you wanted to do :-)

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.