How to loop through days (dates) in bash and force two digits (zerofill)

Often with bash, I need to run a script and pass in a date. It helps to be able to use a bash loop to do it all at once. Here’s how you do it, and make sure the day is two digits. Note the use of the println command.

for day in {1..31}; do php some_script.php 2011-05-`printf "%02d" $day`; done


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>