On 10:55 13 Jun 2003, David Kramer <[EMAIL PROTECTED]> wrote: | On Friday 13 June 2003 04:40 am, Matthew Richards wrote: [...] | > 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
Of course, because grep (and many other command) act as boolean tests, and if's condition test _is_ a command, a much more readbale idom is this: if /bin/grep -qi "serial" /etc/sysconfig/mouse then echo "A serial mouse is attached to this system." else echo "There is not a serial mouse attached to this system." fi No ugly poking at $? required. Cheers, -- Cameron Simpson <[EMAIL PROTECTED]> DoD#743 http://www.cskk.ezoshosting.com/cs/ The impossible we understand right away - the obvious takes a little longer. -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED] https://www.redhat.com/mailman/listinfo/redhat-list