WalaWiki content from p1k3.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

  1. BashTricks. I always forget how to do this, and I'm sick of looking it up for that once every two months when I need it.
  2. * [http://partmaps.org/era/unix/award.html useless use of cat award]
  3. * http://db.ilug-bom.org.in/Documentation/abs-guide/loops1.html
  4. * http://anton.lr2.com/archives/2005/03/24/using-a-bash-for-loop-to-wget/ - Slurp up some of this info.
  5. for arg in [list]
  6. do
  7. command...
  8. done
  9. Don't feel like you have to string this all together on one line when you're doing it in an interactive shell. Just hit enter after each line.
  10. To steal an example:
  11. for planet in "Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto"
  12. do
  13. echo $planet
  14. done
  15. Note that [list] can be the output of a given program - just use backticks, like so:
  16. for doc in `ls *.doc`
  17. do
  18. file $doc
  19. done
  20. A real world example:
  21. for release in `ls`
  22. do
  23. iconv -f iso-8859-1 -t utf-8 ./$release ../converted/$release.html
  24. done
  25. You probably should use globs instead, though:
  26. for release in *
  27. do
  28. foo ./$release
  29. done