0
所以我想創建一個shell腳本來打開四個終端窗口(最好是konsoles)並在每個窗口中運行一個命令,然後保持每個終端都打開,這樣我可以繼續在它們中執行命令(如果需要)。如何編寫一個shell腳本來打開四個終端並在每個終端中執行一個命令?
我試圖按照此處列出的說明:
和
- How can I make a script that opens terminal windows and executes commands in them?
和後試圖那些詳細我最好的是以下幾點:
#!/bin/bash
# some older test, doesn't work and complains and I get this message on command line: "QApplication::qAppName: Please instantiate the QApplication object first"
# I also can't enter text after command executes
#echo "Hello World!"
#exec konsole --noclose -e cat ~/.aliases
# opens terminal but then I can't control terminal afterwards
xterm -hold -e "echo Hello My World"
# didn't do anything
#exit 0
# didn't do anything except make me type exit an extra time where I executed my shell script
#$SHELL
編輯: 使用羅伯託的答案,我得到四個端子這樣的,但我不能輸入其他命令,請注意有像「mycomputername>」沒有任何提示:
編輯2:
我發現一個更好的方式來做我想做的。下面的腳本將執行單獨終端中cmds數組中列出的命令。所以echo'hello1'將在一個終端中運行,echo'hello2'將在另一個終端中運行。這將繼續爲CMDS數組中列出的許多命令
!/bin/bash
# Shell script to open terminals
# and execute a separate command in each
# Commands to run (one per terminal)
cmds=('echo 'hello1'', 'echo 'hello2'')
# Loop through commands, open terminal, execute command
for i in "${cmds[@]}"
do
xterm -e "$i && /bin/tcsh" &
done
使打開了四個終端。我希望每個終端執行一個不同的命令(例如helloworld1,helloworld2,.. 4),這裏的主要問題是我無法控制任何終端。他們各自打開,顯示「Hello World」,但沒有可以在這些新窗口中輸入其他文本的命令行。我在問題中張貼了一張照片,以便您可以看到我在說什麼。 – Veridian
然後你的命令必須是「/ bin/bash」而不是「echo Hello My World」 –
或者「echo Hello My World &&/bin/bash」。這將執行第一個commando(echo),並且如果第一個命令正確結束,將執行shell。 –