使用shell脚本在新的终端标签页中打开程序

5

这是我写的一个小型Shell脚本。

x-terminal-emulator -e "optirun yarpserver" &
sleep 6
x-terminal-emulator -e "optirun iCub_SIM" &
sleep 60
x-terminal-emulator -e "optirun simCartesianControl" &
sleep 30
x-terminal-emulator -e "optirun iKinCartesianSolver --context simCartesianControl/conf --part left_arm" &

这段话的意思是,每次打开一个程序时都会打开一个新的终端窗口。我想要做的是在终端选项卡中打开它而不是在新的终端窗口中打开。我应该如何实现这个效果?

2
你可以在gnome-terminal中完成它:https://dev59.com/43M_5IYBdhLWcg3w3nXz - Piotr Praszmo
1
我似乎无法理解那个问题答案中提供的解决方案,我该如何在这个脚本上实现它。你能否快速详细说明一下? - rajat
1
我在思考这个答案。类似于这个 - Piotr Praszmo
非常好用,谢谢 :) ,但只有一个问题,我看不到打开yarpserver的第一条命令。它会在其他程序能够连接到它时打开,但我看不到它。其他三个都在选项卡中打开。 - rajat
这取决于终端仿真器。(有些仿真器不支持选项卡!) - weakish
2个回答

2
这个帖子真的很老了,但如果有人来到这里,我会留下一个我创建的Bash脚本,用于启动多个标签页以运行不同的命令:
#!/bin/bash

# Array of commands to run in different tabs
commands=(
    'tail -f /var/log/apache2/access.log'
    'tail -f /var/log/apache2/error.log'
    'tail -f /usr/local/var/postgres/server.log'
)

# Build final command with all the tabs to launch
set finalCommand=""
for (( i = 0; i < ${#commands[@]}; i++ )); do
    export finalCommand+="--tab -e 'bash -c \"${commands[$i]}\"' "
done

# Run the final command
eval "gnome-terminal "$finalCommand

只需将命令添加到数组中并执行。

来源: http://joaoperibeiro.com/command-line-script-to-launch-multiple-tabs/


0

我认为你最好的选择是使用tmux来完成这项工作。这里只是一个快速的例子和一步一步的解释。在这里,我仅使用垂直分割,这可能会让你感到困惑,你应该阅读tmux手册以了解如何select-panes

  • 首先在分离模式下创建一个新的tmux会话
  • 然后发送适当的命令启动您的第一个程序
  • 创建一个新的垂直分割
  • 发送适当的命令启动您的第二个程序
  • 以此类推...
tmux new-session -d -s foo
tmux send-keys -t foo 'optirun yarpserver' Enter
tmux split-window -v -t foo
tmux send-keys -t foo 'optirun iCub_SIM' Enter
tmux split-window -v -t foo
tmux send-keys -t foo 'optirun simCartesianControl' Enter
tmux split-window -v -t foo
tmux send-keys -t foo 'optirun iKinCartesianSolver --context simCartesianControl/conf --part left_arm' Enter

希望这能帮助到你。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接