title: Why do sleep & wait in bash?
body: <p>I'm having trouble understanding the startup commands for the services in this <a href="https://github.com/wmnnd/nginx-certbot/blob/master/docker-compose.yml" rel="noreferrer">docker-compose.yml</a>. The two relevant lines from the .yml are:</p>
  
  <pre><code>command: "/bin/sh -c 'while :; do sleep 6h &amp; wait $${!}; nginx -s reload; done &amp; nginx -g \"daemon off;\"'"
  </code></pre>
  
  <p>and</p>
  
  <pre><code>entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h &amp; wait $${!}; done;'"
  </code></pre>
  
  <p>Why send the <code>sleep</code> command to the background and then wait on it? Why not just do <code>sleep 6h</code> directly? Also, is the double dollar sign just escaping the dollar sign in <code>${!}</code>?</p>
  
  <p>I'm finding other places where sleep and wait are used in conjunction, but none seem to have any explanation of why:</p>
  
  <ol>
  <li><a href="http://www.masteringunixshell.net/qa17/bash-how-to-wait-seconds.html" rel="noreferrer">http://www.masteringunixshell.net/qa17/bash-how-to-wait-seconds.html</a></li>
  <li><a href="https://stackoverflow.com/a/13301329/828584">https://stackoverflow.com/a/13301329/828584</a></li>
  <li><a href="https://superuser.com/a/753984/98583">https://superuser.com/a/753984/98583</a></li>
  </ol>