Re: OT: scripting help - can you check a string for starts with?

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

 



Tony Nelson wrote:
At 3:58 PM +0900 12/19/07, John Summerfield wrote:
Tony Nelson wrote:
At 8:48 PM -0500 12/18/07, James Pifer wrote:
Need a bit of scripting help. I have a very small script with a case
statement. The object of the case statement is derived from the
dmidecode command to determine the type of machine it is, if possible.
It works fine, but we're finding that a lot of the HP type machines
respond with a model number plus other information. For example, we
might get these two:

HP Compaq dc7700 30GB6000
HP Compaq dc7700 60GB6000
Here's a real one.
Product Name: HP Compaq dc7700 Small Form Factor

Those are completely made up, the point being that we want to match on
just "HP Compaq dc7700" and forget the rest.
 ...

case $printername in
    "HP Compaq dc7700"*) echo "found $printername" ;;
esac
<chortle>

the example's fine, but read again what he's looking at:-)

Yes, so?  Your "real one" will be found also.  If you think what I said
You _are_ touchy. I was reflecting on the OP's made-up names. What I posted is an actual genuine name chosen by HP.


won't work, give a counterexample.  Perhaps you don't want to nest two case
statements, one for "Produce Name:" and the other for the specific
products?  It's not really needed, as the match strings could all start
with "Product Name:"*.

case $line in
    "Product Name:"*)
        case $line in
            *"HP Compaq dc7700"*) echo "found $printername" ;;
        esac ;;
esac

I was also reflecting on your choice of "printername" for a computer. If you intended it as a joke, fine but I couldn't tell.

--

Cheers
John

-- spambait
1aaaaaaa@xxxxxxxxxxxxxxxx  Z1aaaaaaa@xxxxxxxxxxxxxxxx
-- Advice
http://webfoot.com/advice/email.top.php
http://www.catb.org/~esr/faqs/smart-questions.html
http://support.microsoft.com/kb/555375

You cannot reply off-list:-)

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[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