Re: bash null conditional



On Mon, Mar 30, 2009 at 11:27:42AM -0700, Craig White wrote:
I'm in my bash book and looking on web but can't seem to resolve this
simple problem.

$ if [ -n "grep A121 myfile.csv" ]; then echo "null"; fi
null

$ if [ -n "grep A125 myfile.csv" ]; then echo "null"; fi
null

A125 definitely is null when I just run the grep command in the quotes
but A121 definitely is not null.

What am I missing on the if/null operator here?

Craig

if you're doing classwork and required to use the if (and related)
operators, then my response isn't what you want.

But if you just want to know how to get equivalent functioniality,
you may wish to consider this:

grep A125 myfile.csv || echo "no match found"

which runs the grep and if not "successful" (i.e., did not find a match)
it runs the echo command.

alternatively:

grep A125 myfile.csv && echo "found a match"

does the echo if it DID find A125.

Fred
--
-------------------------------------------------------------------------------
Under no circumstances will I ever purchase anything offered to me as
the result of an unsolicited e-mail message. Nor will I forward chain
letters, petitions, mass mailings, or virus warnings to large numbers
of others. This is my contribution to the survival of the online
community.
--Roger Ebert, December, 1996
----------------------------- The Boulder Pledge -----------------------------

Attachment: pgp7qOS6Y2vMe.pgp
Description: PGP signature

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

Relevant Pages

  • Re: repalce the some lines of file1 to file2
    ... The double quotes are within single quotes and taken literally. ... if grep "^$line:" passwd ... echo "$DESTLINE" ...
    (comp.lang.awk)
  • Re: bash null conditional
    ... A125 definitely is null when I just run the grep command in the quotes ... bash: [: too many arguments ...
    (Fedora)
  • Re: bash null conditional
    ... A125 definitely is null when I just run the grep command in the quotes ... This will actually invoke 'grep' and insert its output into the string ...
    (Fedora)
  • Re: unix pipe command
    ... suppose i m running a grep command will give result whos size is 1GB. ... Then there is a issue with your terminal's scroll back buffer, ... and is not strictly related to "where does grep store output ...
    (comp.unix.shell)
  • RE: Connection refused when trying to connect
    ... It will not display your grep command in the output. ... $ ps aux | grep httpd ... unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe ...
    (RedHat)