When I first learned about Linux in the 90’s, I read that it was possible to even write your own commands to use at the command line. Later I learned about bash scripting, and it wasn’t long before I needed to learn how to loop in bash. Looping in bash is one of the fundamental building blocks of bash programming. It isn’t hard to do at all and is worth learning. The main reason to learn looping in bash is to handle doing the same thing over and over again. They’re easy to do even at the command line. Please follow along as we look a couple of basic examples, and how you can expand on them.
http://www.tidbitsfortechs.com/2014/10/looping-in-bash/
(Score: 1) by b on Sunday October 12 2014, @10:59AM
Yeah, I thought this felt like useless use of cat too, but I'm not sure how it could be improved. I'm not sure how to remove cat from "for i in $(cat foo.txt)".
(FWIW I'd use "while read -r" myself anyway.)
(Score: 2) by Foobar Bazbot on Monday October 13 2014, @01:00AM
9 times out of 10 (i.e. unless one really means to allow multiple iterations per line), the right way to remove cat from "for i in $(cat foo.txt)" is to remove the whole line.
(FWIW I'd use "while read -r" myself anyway.)
You and me both.
(Score: 1) by b on Monday October 13 2014, @11:42PM