Skip to content

Instantly share code, notes, and snippets.

@jj1bdx
Created June 2, 2014 04:02
Show Gist options
  • Star 48 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jj1bdx/ac043f442cc6c30f42de to your computer and use it in GitHub Desktop.
Save jj1bdx/ac043f442cc6c30f42de to your computer and use it in GitHub Desktop.
A shell one-liner for an infinite loop (sh/zsh/bash compatible)
while true; do date; sleep 5; done
@jj1bdx
Copy link
Author

jj1bdx commented Sep 15, 2020

@mhjb 👍

@victor-yarema
Copy link

If you don't need to support sh then why bother with do and done?
for ((;;)) { date ; sleep 1 ; }
I find this one more readable because of curly brackets.

@roblogic
Copy link

roblogic commented Dec 1, 2020

for ((;;))date&&sleep 1 even fewer bytes, in zsh at least :)

@sergio-opslevel
Copy link

Just what I needed. Thanks!

@jj1bdx
Copy link
Author

jj1bdx commented Jun 1, 2021

@jj1bdx
Copy link
Author

jj1bdx commented Jun 1, 2021

I've got nothing personal against zsh or bash, and I appreciate shorter scripts posted for bash and zsh. Still, maintaining the backward compatibility even in such a small script like in this gist is important.

@earayu
Copy link

earayu commented Jul 9, 2023

Nice

@asgs
Copy link

asgs commented Jan 8, 2024

And I thought indenting is a must like it's in python. Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment