使用bash脚本在gnome-terminal中为每个终端选项卡设置标题

我正在使用Ubuntu 16.04

我想打开多个终端选项卡,运行命令并设置标题。 我可以使用此命令打开多个选项卡:

gnome-terminal --tab -e "command1" --tab -e "command2" 

但不能使用--title选项,因为它在此版本中不可用。

我知道mate-terminal可以做到这一点,但我想使用gnome-terminal。

我已经应用了这里发布的解决方案,但是当我运行的时候它可以运行

 gnome-terminal --tab -e "bash -c 'set-title 99;ping 192.168.7.99'" 

表明:

 bash: set-title: command not found PING 192.168.7.99 (192.168.7.99) 56(84) bytes of data. 64 bytes from 192.168.7.99: icmp_seq=1 ttl=128 time=0.425 ms 64 bytes from 192.168.7.99: icmp_seq=2 ttl=128 time=0.353 ms 64 bytes from 192.168.7.99: icmp_seq=3 ttl=128 time=0.335 ms 

我还在Unix和Linux SE上应用了这里提出的解决方案

我也阅读了这篇文章设置 – 终端 – 标题 – 标题但是接受的答案没有解决我在16.04 os或gnome-terminal 3.18.3版本中的问题,而其他解决方案提供了使用其他终端xterm而我想使用gnome-终奌站。

如果要使用存储在~/.bashrc的函数,请在命令中获取该文件:

 gnome-terminal --tab -e "bash -c 'source ~/.bashrc;set-title 99;ping 192.168.7.99'" 

您已在评论中提到计划在shell脚本和多个gnome-terminal选项卡中使用它。 作为概念certificate,您可以使用以下脚本作为示例:

 #!/bin/bash gnome-terminal --tab -e "bash -c 'printf \"\033]0;TEST1\007\"; sleep 7'" \ --tab -e "bash -c 'printf \"\033]0;TEST2\007\"; ping -c 4 8.8.8.8'" \ 

而不是bash函数,它直接使用printf和转义序列。 请注意反斜杠。