【问题标题】:Open a program in new terminal tab using shell script使用 shell 脚本在新的终端选项卡中打开程序
【发布时间】:2012-10-09 07:47:33
【问题描述】:

这是我写的一个小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" &

这样做是为每个程序打开一个新终端。我想要做的是打开新的终端选项卡而不是终端。我该怎么做呢?

【问题讨论】:

  • 你可以在 gnome-terminal:stackoverflow.com/questions/1188959/…
  • 我似乎无法从该问题的答案中理解解决方案,我该如何在此脚本上执行此操作。能否请您快速详细说明?
  • 我在想this 的答案。类似this
  • 工作就像一个魅力谢谢:),但只有一个问题我看不到打开 yarpserver 的第一个命令。它打开了,因为其他程序能够连接到它,但我看不到它。所有其他 3 个都在选项卡中打开。
  • 这取决于终端仿真器。 (有些模拟器不支持选项卡!)

标签: shell


【解决方案1】:

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

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

希望对你有所帮助。

【讨论】:

    【解决方案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/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-05
      • 2023-04-04
      • 2013-11-18
      • 1970-01-01
      • 2014-07-31
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多