【发布时间】:2017-02-24 17:18:52
【问题描述】:
所以我正在尝试创建一个 shell 脚本来打开四个终端窗口(最好是 konsoles)并在每个终端窗口中运行一个命令,然后让每个终端保持打开状态,以便我可以在需要时继续在其中执行命令。
我尝试按照此处列出的说明进行操作:
和
在尝试了这些细节之后,我得到的最好的结果如下:
#!/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
【问题讨论】:
标签: linux shell unix scripting xterm