knowledge/technology/applications/cli/Loop.md
2023-12-04 11:02:23 +01:00

1.1 KiB

obj os repo
application linux https://github.com/Miserlou/Loop

Loop

Repo
Loops in bash are surprisingly complicated and fickle! I wanted a simple and intuitive way to write controllable loops that:

  • Run on controllable timers!
    • $ loop --every 10s -- ls
  • Have custom counters!
    • $ loop --count-by 5 -- 'touch $COUNT.txt'
  • Loop until output matches a condition!
    • $ loop --until-contains 200 -- ./get_response_code.sh --site mysite.biz
  • Loop until a certain time!
    • $ loop --for-duration 8h -- ./poke_server
  • Loop until a program succeeds (or fails!)
    • $ loop --until-success -- ./poke_server
  • Iterate over the standard input!
    • $ cat files_to_create.txt | loop -- 'touch $ITEM'
  • Get a summary of the runs!
    • $ loop --for-duration 10min --summary -- ls
  • Run until output changes or stays the same between invocations!
    • $ loop --until-changes -- date +%s
    • $ loop --until-same -- date +%s
  • ..and much more!