[opensuse] Re: BASH - better way to get total number of files matching glob??
Jon Clausen wrote:
So if one has to do 'file type' operations on the objects later, one would have to amend the code with some [ -f ${array[$i]} ] -ish tests, which might end up eating away whatever performance gain one got to begin with.
Tip: *Always* write [ -f "${array[$i]}" ]. Never leave off the double quotes, even if you think you know that the array element's value will not have white space. Make that a habit, and you'll write better shell scripts: Always use double quotes around shell variable expansions and single quotes around literal strings. 75% of all quoting errors will be gone. Joachim -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Joachim Schrod Email: jschrod@acm.org Roedermark, Germany -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Mon, 07 Jun, 2010 at 13:05:39 +0200, Joachim Schrod wrote:
Jon Clausen wrote:
So if one has to do 'file type' operations on the objects later, one would have to amend the code with some [ -f ${array[$i]} ] -ish tests, which might end up eating away whatever performance gain one got to begin with.
Tip: *Always* write [ -f "${array[$i]}" ]. Never leave off the double quotes, even if you think you know that the array element's value will not have white space.
Make that a habit, and you'll write better shell scripts: Always use double quotes around shell variable expansions and single quotes around literal strings. 75% of all quoting errors will be gone.
The "-ish" is key here: I didn't mean it literally, but only to illustrate that one might have to 'filter' out undesired objects from a list of all kinds of objects. /jon -- YMMV -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (2)
-
Joachim Schrod
-
Jon Clausen