Bash 脚本。打开新终端和 运行 命令

Bash script. Open new terminal and run command

如何从 bash 在新终端中 运行 命令? 如果我 运行 它只是来自一个终端, mosquitto_sub - 阻止脚本。 xterm -e 打开新终端,但我的脚本也被阻塞了...

 #!/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 "[=12=]7"
     fi
             cat "/root/Desktop/ScreenTool/image/output.txt"
    sleep 3;
  done

要在不等待命令完成的情况下执行命令,请使用 & 将其置于后台。

#!/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 "[=10=]7"
    fi
    cat "/root/Desktop/ScreenTool/image/output.txt"
    sleep 3;
done