On Friday 13 June 2003 04:40 am, Matthew Richards wrote: > Hello, > > I am writing a script to determine if a serial mouse is connected to the local system. So far I have: > > #!/bin/bash > SMOUSE=$(/bin/grep -i "serial" /etc/sysconfig/mouse) > if [ $SMOUSE = "" ]; then > echo "There is not a serial mouse attached to this system." > else > echo "A serial mouse is attached to this system." > fi <SNIP> > the value that is returned on my system with a serial mouse is: > > FULLNAME="Generic - 3 Button Mouse (serial)" > > but I do not know how to determine if the string "serial" exists in the variable SMOUSE in terms of the 'if' statement.
The answer is.... you don't. If you specify the -q option, grep will exit immediately with zero status if any match is found (even if an error was detected), or non-zero if no match is found. The $? shell variable is always set to the exit code of the previous command, so just check that. /bin/grep -qi "serial" /etc/sysconfig/mouse if [ $? != 0 ]; then echo "There is not a serial mouse attached to this system." else echo "A serial mouse is attached to this system." fi ------------------------------------------------------------------- DDDD David Kramer http://thekramers.net DK KD "If I asked you where we were," said Arthur weakly, "would I DKK D regret it?" Ford stood up. "We're safe," he said. "We are DK KD in a small galley cabin," said Ford, in one of those DDDD spaceships of the Vogon Construction Fleet." "Ah." said Arthur, "this is obviously some strange usage of the word _safe_ that I wasn't previously aware of." Douglas Adams, "Hitchhiker's Guide to the Galaxy". -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED] https://www.redhat.com/mailman/listinfo/redhat-list