如何从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 "\007"
fi
cat "/root/Desktop/ScreenTool/image/output.txt"
sleep 3;
done
答案 0 :(得分: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