Bash Script: For-Loop Over Newline… Syntax Explained?
A frequently asked question both on SO and elsewhere is how to use a bash for-loop to go over each line of output. I'm aware of the answer, and I've been happily using the following for years now:
However, I'm slightly perplexed by the syntax used. I've had a good search / Google, but due to the sheer number of symbols which are used / ignored by search engines in the above - I've not found an explanation.
I've also recently spotted this in some output from another script. I was having problems echoing the result from netcat. Upon closer inspection, it turns out that the output from nc was in a similar format:
I ended up needing to cut off the \r, but wasn't sure of the best way to go about it, I ended up using egrep -o ([0-9|a-Z]*). Any better ideas?
The Bash manual explains this quoting method, which it calls ANSI-C Quoting.