Re: bash null conditional

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

 



On Mon, 2009-03-30 at 13:42 -0500, Robert Nichols wrote:
> 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.
----
yeah...I actually started with backticks and was trying various things.

This seems to work...

$ if [ `grep -c A121 myfile.csv` -eq 0 ]; then echo "null"; fi
$ if [ `grep -c A125 myfile.csv` -eq 0 ]; then echo "null"; fi
null
$

but if someone clarifies the -n (null) result, I would be grateful.

Thanks

Craig

-- 
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