Find the answer to your Linux question:
Results 1 to 5 of 5
Hey, the following shell script executes but does absolutely nothing. It is meant to switch the synaptics touch pad on if it's off or off if it's on. Any ideas? ...
  1. #1
    Linux Newbie chadders's Avatar
    Join Date
    Jan 2007
    Location
    Earth.
    Posts
    102

    A little help with a shell script

    Hey,

    the following shell script executes but does absolutely nothing. It is meant to switch the synaptics touch pad on if it's off or off if it's on. Any ideas? I think it's something to do with the string comparison.

    Code:
    question="`synclient -l | grep TouchpadOff`"
    
    echo $question
    
    if [[ $question == "TouchpadOff = 1" ]]
    then
    
    synclient TouchpadOff=0 
    
    else
    
    synclient TouchpadOff=1 
    
    fi
    Thanks in advance,

    chadders.
    That's my two pence worth.

    Chadders.

    Use my themes... click here.

    New to Linux Forums, or Linux in general? Start here.
    Get Debian (Etch) here.
    Registered Linux user #442544.

  2. #2
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Read this:
    http://www.tldp.org/LDP/abs/html/sha-bang.html

    Also, run your script like so:
    bash -x ./script-here

    You can watch it as it executes to see which statements are being run, variable assignments, etc.

  3. #3
    Linux Newbie chadders's Avatar
    Join Date
    Jan 2007
    Location
    Earth.
    Posts
    102
    Help? To me it appears as though a list of characters is being compared to a string (if it's even a string). How can I rectify this?

    Code:
    chadders@laptop:~/Desktop$ bash -x touchpad.sh
    ++ synclient -l
    ++ grep TouchpadOff
    + question='    TouchpadOff          = 1'
    + echo TouchpadOff = 1
    TouchpadOff = 1
    + [[     TouchpadOff          = 1 == \T\o\u\c\h\p\a\d\O\f\f\ \=\ \1 ]]
    + synclient TouchpadOff=1
    That's my two pence worth.

    Chadders.

    Use my themes... click here.

    New to Linux Forums, or Linux in general? Start here.
    Get Debian (Etch) here.
    Registered Linux user #442544.

  4. #4
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Don't forget to add your sha-bang.

    I think the problem is with whitespace in the left side of your conditional test. Try this:
    [[ $(echo $question | tr -d ' ') == 'TouchpadOff=1' ]]

    Squeeze out the spaces so that you can compare easily.

    See how helpful that debugger is? You can see the white space in the variable assignment operation.

  5. #5
    Linux Newbie chadders's Avatar
    Join Date
    Jan 2007
    Location
    Earth.
    Posts
    102
    yup that worked perfectly. Thanks a lot . I'm still new to shell scripting but at least I'm not a complete newbie lol :P
    That's my two pence worth.

    Chadders.

    Use my themes... click here.

    New to Linux Forums, or Linux in general? Start here.
    Get Debian (Etch) here.
    Registered Linux user #442544.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...