2017-07-03 328 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,求救! –

相關問題