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

Re: shell game

    "Bob" == Bob Proulx <bob@proulx.com> writes:

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

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

Good catch Bob! Funny thing is that when I wrote this at the shell
prompt to test it I actually did stick a character in (I use 'z'
instead of an underscore, some old habit). I took it out so I would
not have to explain why it was there. In retrospect I should've, no
point in spreading bad habits :-(


Reply to: