0

i will go and see if my touch screen calibrated with a own script. But i have really few experience with shell scripts. I hope anyone can help me.

My idea is it to execute xinput --list-pros <device> and check the terminal output with the entry ...(242): <no items>. This is the option if the touch screen not calibrated else there are the x/y coordinates like ...(242): 1 22 333 4444.

In my script I will execute xinput --list-pros <device> and check with grep is there a entry (242) and then check the same line if there a entry <no items>. But i fail to read the output from xinput --list.

# read the terminal output from xinput
$xinput_output= less xinput --list-pros 7

    while read $xinput_output
    do
         # check first line from output
         grep "242" $xinput_output
         if [ $? != 0]
         then
             break;
         else
             # found 242 check x/y coordinates
             grep "<no items>" $xinput_ouput
             if [ $? != 0]
             then
                 #no x/y coordinates, execute xinput_calibration
                 xinput_calibration
                 exit 0
             fi
         fi

    done < $1
Arnab Nandy
  • 6,472
  • 5
  • 44
  • 50
zombinary
  • 67
  • 9

4 Answers4

0

Enclose your command with backtick or $():

var=`some command`  # note no $ before var
# Or by $()
var=$(some command)

# then you can now use command's output
echo $var
jrarama
  • 904
  • 7
  • 8
  • Note that whilst still popular, backticks have effectively been deprecated. See http://stackoverflow.com/questions/4708549/shell-programming-whats-the-difference-between-command-and-command for a good explanation. – declension Jan 22 '15 at 13:08
  • @NickB Backticks are actually not deprecated. $() is an alternative to be able to nest commands: http://unix.stackexchange.com/a/126928 – jrarama Jan 22 '15 at 13:30
  • 1
    @jrarama See first comment "By most of the meanings of deprecated, I (and you) would say that backticks are deprecated. It's mostly a terminology question. – Stéphane Chazelas Apr 28 '14 at 15:54" . And a little later " ...I have never heard an argument for continuing to use them in new code." – shellter Jan 22 '15 at 17:03
0

Presumably you mean xinput --list-props

Either way, you need to execute the command properly in bash, and you need to assign the variable properly, so try this:

xinput_output=$(xinput --list-props 7)
declension
  • 4,110
  • 22
  • 25
0

Thanks for your help,

i had a solution which works. But i will advance it a little bit. I will remove the 'touch' command and will write the './demo' output in a memory not in a file. Not be confused I change 'xinput' for testing in my own skript './demo', this is a script with only few 'echo' commands to generate a terminal output.

    #filename: touch
    #!/bin/bash

            touch /tmp/tmp.log
            ./demo > /tmp/tmp.log

            calibration=$(grep controller /tmp/tmp.log)
        if [ $? != 0 ]
        then
            echo "missing match, corrupt file\n"
            exit 0
        fi

        if [[ $calibration == *"<no items>"* ]]
        then
            echo no calibration
            #xinput_calibration
        else
            echo found x/y coodinates
        fi

        rm /tmp/tmp.log

        exit0

test script:

#filename: demo
#!/bin/bash

echo 'cookie'
echo 'cookie'
echo 'cookie'
controller\:\ \<no\ items\>
echo 'cookie'
echo 'cookie'
echo 'cookie'

exit 0
zombinary
  • 67
  • 9
0

i ****found** the solution**. :D \"/,

My problem was, with

tmp=$(./demo)
echo $tmp

you put out the terminal output from ./demo as string. and with 'grep' you can't find a single line. So you must type "${tmp}" to find the single line with grep.

#cache terminal output
    tmp=$(./demo)
#find word in cache
    match=$(echo "${tmp}" | grep 'controller')
    echo $match
zombinary
  • 67
  • 9