mention of PS2. Anyone who uses it will
not see the default that you have.
Telling people to use a for file in $(grep
-l stuff...) is bad practice. The
construct will fail if the filenames have
embedded whitespace. Also, it will fail if
the list is large, because you will violate
the maximum length of a command.
The use of square brackets is to denote
optional use. I strongly encourage you to
read the Bash man page.
The proper way to do it is either to
use a while read loop, or to use
find | xargs. It’s almost always a
bad idea to usefind -exec:
find . -type f -print0 | xargs -0 grep -l stuff
The same thing using while read
and process substitution might be:
while read fn
done <(< find | xargs...)
This is exactly two subprocesses.
You mentioned a 250-line script (scale),
but you don’t tell us where it is so we
can see it. But, it bears mentioning
that there is a big difference between
options and their possible option
arguments, and command arguments.
Looking forward to the next one.
—Steven W. Orr
Thanks for Covering the Basics
I just read Dave Taylor’s column in the
July 2012 Linux Journal (“Subshells and
Command-Line Scripting”) and wanted to
say thanks. Although Dave’s other shell
articles provide insight into using the shell,
I usually end up planning to read those
in depth sometime later, and then don’t.
I enjoy articles that explain the basics in
more depth. While I am not a newbie
(I started more seriously when Fedora Core
1 came out), I am not very advanced. My
occupation was as a toolmaker at an R&D
facility, and my family consumed (I’m now
retired) much of my time and thought. I
am probably still, at best, a beginning-intermediate Linux adherent/user. I want
to develop a much deeper understanding
of all aspects of how Linux works, and