* Matthew Richards > 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 > > However, this script fails because there is a space or newline character or > something in the grep output. I have considered taking another approach, such as > looking for the word serial in the grep output, but I am unsure how to do this. If I > add the following line: > > echo $SMOUSE > > 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. > > Can anyone please suggest how I can make this script work.
First, the way to use grep and if is usually like this: if grep -i "serial" /etc/sysconfig/mouse >/dev/null; then echo "yes" else echo "no" fi Second, all you have to do to make your line work is to enclose $SMOUSE in quotes: if [ "$SMOUSE" = "" ]; then What happens in your case is that after variable expansion you get: if [ FULLNAME="Generic - 3 Button Mouse (serial)" = "serial" ]; then and such a sentence does not make sense, does it? Third, your script will fail anyway, because I do have a mouse, but I do not have the word "serial" in the said file. (A wild guess for one approach is to do something like: if grep '\*\*.*Mouse' /var/log/XFree86.0.log >/dev/null; then echo yes; else echo no; fi) -- Jon Haugsand, [EMAIL PROTECTED] http://www.norges-bank.no -- redhat-list mailing list unsubscribe mailto:[EMAIL PROTECTED] https://www.redhat.com/mailman/listinfo/redhat-list