[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: bash null conditional
- From: Robert Nichols <rnicholsNOSPAM comcast net>
- To: fedora-list redhat com
- Subject: Re: bash null conditional
- Date: Mon, 30 Mar 2009 13:42:58 -0500
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?
As written, you are asking if the literal string "grep A121 myfile.csv"
is non-null, which obviously is true and has nothing whatsoever to do
with the 'grep' command, which is never invoked.
$ if [ -n "`grep A121 myfile.csv`" ]; then echo "null"; fi
This will actually invoke 'grep' and insert its output into the string
to be tested.
--
Bob Nichols "NOSPAM" is really part of my email address.
Do NOT delete it.
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]