Created
May 1, 2019 16:17
-
-
Save chris-sun/9126fc162d9f1aa63758e22666c71165 to your computer and use it in GitHub Desktop.
Shell script - while loop example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
MAX_TRIES=100 | |
TRIES=0 | |
OUTPUT=/tmp/output.txt | |
while [ $TRIES -lt $MAX_TRIES ] | |
do | |
# run some command here, "ls -l" is used below | |
ls -l | |
EXIT_VAL=$? | |
echo "********************" | |
echo "EXIT_VAL: ${EXIT_VAL}" | |
if [ $EXIT_VAL -ne 0 ] | |
then | |
echo $OUTPUT | |
# say command only works on Mac | |
say "A failure happened. Awesome" | |
fi | |
TRIES=`expr $TRIES \+ 1` | |
echo "Num tries: ${TRIES}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment