Bob Crandell wrote:

> I'm trying to write a script that checks the contents of a file and
> if it's there skip it.

        $!/bin/sh
        if grep -wq local /etc/hosts
        then
            echo "Been there.  Done that."
        else
            echo "It's okay to do it now."
        fi

The conditional (the part between "if" and "then") is an arbitrary
command.  It evaluates true if the command returns zero.  "[" is a
shell built-in that returns zero or nonzero based on things that
look like boolean expressions in other languages.

Note that I added a "-w" flag to grep.  That matches "local" as a
whole word, and not as part of "localhost".  If that's not what you
want, remove the "-w" flag.

The "-q" flag is obvious.

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     [EMAIL PROTECTED]
_______________________________________________
EuG-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug

Reply via email to