You're viewing a comment by dj and its responses.

December 09, 2013, 18:07

cat file | while... should be avoided. It isn't a like or dislike but is technically different. The pipe creates a subprocess, which has overhead and variable scope issues.

This is only a comment, but it would be better to show them doubled-quoted. The comment might change to an echo and newbies might get the wrong idea. Quoting for splitting, expansion and special characters is probably the biggest gotcha and most misunderstood bash topic.

# do something with $field1, $field2, and $field3
echo do something with "$field1", "$field2", and "$field3"

These should be quoted too, like:
echo $lines
echo $words
echo $chars
echo "$lines"; echo "$words"; echo "$chars"

Reply To This Comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the first letter of your name: (just to make sure you're a human)

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