2017-07-03 273 views
0

如何在bash的新终端中运行命令? 如果我只是从一个终端运行它,mosquitto_sub - 阻止脚本。 xterm -e打开新的终端,但我的脚本块太...Bash脚本。打开新的终端并运行命令

#!/bin/bash 
     COUNTER=0 
    xterm -e mosquitto_sub -h 192.168.1.103 -t test 
    mosquitto_pub -h 192.168.1.103 -t test -m "Connected" 
    cd Desktop/ScreenTool/image/ 
     while [ $COUNTER == 0 ]; do 
     tesseract c.png output 
    if grep -q Click "/root/Desktop/ScreenTool/image/output.txt"; then 
     mosquitto_pub -h 192.168.1.103 -t test -m "Rain is here" 
     echo -en "\007" 
    fi 
      cat "/root/Desktop/ScreenTool/image/output.txt" 
    sleep 3; 
    done 
+0

在xterm的情况下,如果关闭“新终端”,脚本继续。 –

回答

1

,而无需等待它完成,把它的背景&执行命令。

#!/bin/bash 
COUNTER=0 
xterm -e mosquitto_sub -h 192.168.1.103 -t test & 
mosquitto_pub -h 192.168.1.103 -t test -m "Connected" 
cd Desktop/ScreenTool/image/ 
while [ $COUNTER == 0 ]; do 
    tesseract c.png output 
    if grep -q Click "/root/Desktop/ScreenTool/image/output.txt"; then 
     mosquitto_pub -h 192.168.1.103 -t test -m "Rain is here" 
     echo -en "\007" 
    fi 
    cat "/root/Desktop/ScreenTool/image/output.txt" 
    sleep 3; 
done 
+0

thnx,求救! –

相关问题