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?

while true; do
    OUTPUT="$(docker inspect --format='{{json .State.Health.Status}}' su-apache)"
    if [ $OUTPUT = '"healthy"' ]; then
    echo -en "\r\033[KWaiting $i seconds for su-apache to finish starting... Current health: $OUTPUT"
    let "i++"
    sleep 1

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
    # ...

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\$ 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
    Sep 15, 2016 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.