Article 598NR Help with bash for loop

Help with bash for loop

by
woodson2
from LinuxQuestions.org on (#598NR)
The code below works just fine as long as the exit status equals 0, however I'd like the script to exit after 3 times if the exit status is non-zero. Right now the script continues on even if the exit status is non-zero after the 3 iterations.

Code:for run in {1..3}
do
kinit $USER
if [ $? -eq 0 ]; then
echo ""
echo -e "${bldgrn}Good. Now lets us continue${txtrst}"
echo ""
sleep .5
break
else
sleep 1
echo -e "${bldred}Please verify your credentials and try again!${txtrst}"
fi
donelatest?d=yIl2AUoC8zA latest?i=AtstJK2PQNQ:-7ARv4r6r9k:F7zBnMy latest?i=AtstJK2PQNQ:-7ARv4r6r9k:V_sGLiP latest?d=qj6IDK7rITs latest?i=AtstJK2PQNQ:-7ARv4r6r9k:gIN9vFwAtstJK2PQNQ
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments