[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell game



Shyamal Prasad <shyamal.prasad@sbcglobal.net> [2002-12-07 13:53:57 -0600]:

> if [ "`find . -maxdepth 1 -name '*.jpg' -print`" != "" ]

A very slight danger here.  If the first filename starts with a '-'
then test will see this as an option instead of as a string and
complain.  This is why people prefix with a known character.  Usually
using an '_' or 'X' or whatever the programmer prefers.  This is
safer.  This is typical when comparing against a non-zero sized
string.

  if [ _"`find . -maxdepth 1 -name '*.jpg' -print`" != _"" ]

However, if you are only testing against a zero length string as here
then using the test operators -z or -n work well without the extra
safeguarding.

  if [ -n "`find . -maxdepth 1 -name '*.jpg' -print`" ]

Bob

Attachment: pgpgseJSpnkgU.pgp
Description: PGP signature


Reply to: