linux - shell,匹配终端输出中的字符串

标签 linux bash shell grep

我会去看看我的触摸屏是否使用自己的脚本进行了校准。 但我对 shell 脚本的经验真的很少。我希望任何人都可以帮助我。

我的想法是执行xinput --list-pros <device>并使用条目 ...(242): <no items> 检查终端输出。 如果触摸屏未校准,则可以选择此选项,否则会出现 x/y坐标如...(242): 1 22 333 4444 .

在我的脚本中,我将执行 xinput --list-pros <device>并检查 grep有条目(242)然后检查同一行是否有条目 <no items> 。但我无法读取 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

最佳答案

用反引号或 $() 将命令括起来:

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

# then you can now use command's output
echo $var

关于linux - shell,匹配终端输出中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28089341/

相关文章:

linux - 在 Expect 中处理文件

linux - 通过 Sublime text 保存在 Ubuntu 终端上完成的工作

linux - 仅适用于一个进程的挂载点/符号链接(symbolic link)

regex - 如何解决正则表达式中的问题?

c++ - Linux 守护进程 - 运行函数两次

linux - 显示名称包含空格的文件大小

bash - Shell 脚本读取缺少最后一行

linux - 在文件夹中查找文件夹的命令

linux - 如何在shell脚本文件的每一行末尾添加一个字符

linux - 在 bash shell 脚本中切换用户