shorter for-loops in zsh

When running a for-loop in zsh, you can skip do-done part, leaving only command, for example:

% for day in Mon Tue Wed Thu; date -d "next $day"
Mon Apr 25 00:00:00 CEST 2016
Tue Apr 26 00:00:00 CEST 2016
Wed Apr 27 00:00:00 CEST 2016
Thu Apr 28 00:00:00 CEST 2016

Caveat: this doesn’t work on multiple commands in one loop — for day in Mon Tue Wed Thu; echo $day; date -d "next $day" won’t work as expected

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.