I'm looking to improve it in brevity, readability, and simplicity. Basically, I'm just looking for a more elegant solution. What improvements can I make?
i=0
while true; do
OUTPUT="$(docker inspect --format='{{json .State.Health.Status}}' su-apache)"
if [ $OUTPUT = '"healthy"' ]; then
echo
break
fi
echo -en "\r033円[KWaiting $i seconds for su-apache to finish starting... Current health: $OUTPUT"
let "i++"
sleep 1
done
echo 'Environment started successfully.'
1 Answer 1
If you don't mind using Bash,
then it will be more elegant to replace the while
loop with a counting for
loop:
for ((i = 0; ; i++)); do
# ...
done
I'm guessing that you're using Bash anyway from the let "i++"
syntax,
which will not work with simpler shells like Dash.
Note that the various flags of echo
are not portable.
For a more portable solution, replace it with printf
.
Lastly, the indentation is inconsistent: some blocks are indented with 4 spaces, others with 2. It would be better to indent consistently (I like 4 spaces).
-
\$\begingroup\$ Thanks for this. It really helped a lot! How are things normally done here on CodeReview? How long do people usually wait before accepting an answer? Should I edit my revised code into my question? \$\endgroup\$Nathan Arthur– Nathan Arthur2016年09月15日 21:17:11 +00:00Commented Sep 15, 2016 at 21:17
-
\$\begingroup\$ Hi, and welcome! I don't recall a rule for this. A few days on average is usually about right, I guess. We don't edit code in the question, as that would invalidate answers. See this page in the help center for more details, and enjoy the site! \$\endgroup\$janos– janos2016年09月15日 21:57:00 +00:00Commented Sep 15, 2016 at 21:57
Explore related questions
See similar questions with these tags.