Re: bash null conditional

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

 



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: pgpSyeU1klgmb.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
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux