You're viewing a comment by Dave Eddy and its responses.

June 08, 2012, 10:48

Great post, you covered awesome stuff, and unlike most bash tips, you actually understand bash and all the gotchas it has.

One quick note on #4, where you cat the file and | into while read line, be careful with this approach. The while loop is now created in a subshell, so any variables modified within the context of the while loop will not persist when the loop exits.

ex. (let's say foo.txt has 10 lines)

cat foo.txt | while read line; do ((i++)); done
echo "$i"

will print 0.

Comment Responses

April 15, 2014, 07:33

Do it ike this:
i=0;cat foo.txt | (while read line; do ((i++)); done; echo "$i")

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "apple_325": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.