Mac OS X Terminal – While True Do – Can you stop automatically under desired conditions

macpythonterminal

Currently I am using a following command: while true; do python [file]; sleep X; done

I was wondering if I can stop the loop if the result prints a word that I'm looking for.

Plus is it possible to make a sound when it stops?

Best Answer

You can stop the execution by entering the command break.

To make a sound, tput bel should work on most shells.

Something like the following example should work:

while true
do
     commands...

     if [[ "$YOUR_VARIABLE" == "value" ]]
     then
         tput bel
         break
     fi
done