Gab*_*les 5 bash scripts gnome-terminal bashrc source
cd进入每个选项卡中的不同文件夹(即:运行唯一的命令)。 我想要编写此脚本,以便我可以单击桌面上的脚本并让它打开终端,就像我想要的日常开发环境一样。
\n\n我有这个脚本来尝试打开 3 个终端选项卡,并在选项卡中运行独特的命令:
\n\n#!/bin/bash\n\ngnome-terminal --tab -- bash -c "source $HOME/.bashrc && set-title hey; exec bash"\ngnome-terminal --tab -- bash -c "cd ~; exec bash"\ngnome-terminal --tab\nRun Code Online (Sandbox Code Playgroud)\n\n当我使用 运行它时./open_tabs.sh,它会打开 3 个新选项卡,但不幸的set-title是无法设置选项卡标题!我在打开的选项卡中收到此错误:
bash: set-title: command not found\nRun Code Online (Sandbox Code Playgroud)\n\n我已经像这样set-title定义了一个函数~/.bashrc。其目的是在任何终端窗口的顶部设置标题字符串。当我手动使用它时它工作得很好。例如:set-title hey how are you?将输入“嘿,你好吗?” 在我的终端窗口的顶部。
# From: https://unix.stackexchange.com/questions/177572/how-to-rename-terminal-tab-title-in-gnome-terminal/566383#566383\nset-title() {\n # If the length of string stored in variable `PS1_BAK` is zero...\n # - See `man test` to know that `-z` means "the length of STRING is zero"\n if [[ -z "$PS1_BAK" ]]; then\n # Back up your current Bash Prompt String 1 (`PS1`) into a global backup variable `PS1_BAK`\n PS1_BAK=$PS1 \n fi\n\n # Set the title escape sequence string with this format: `\\[\\e]2;new title\\a\\]`\n # - See: https://wiki.archlinux.org/index.php/Bash/Prompt_customization#Customizing_the_terminal_window_title\n TITLE="\\[\\e]2;$@\\a\\]"\n # Now append the escaped title string to the end of your original `PS1` string (`PS1_BAK`), and set your\n # new `PS1` string to this new value\n PS1=${PS1_BAK}${TITLE}\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我该如何解决!?我已经尝试了exporting 和sourceing,只是不知道我在这里做错了什么。
打开具有多个选项卡的终端并执行应用程序<== 这就是我真正想要解决的问题,但是gnome-terminal\'s --command( -e) 选项现已弃用!
# Option \xe2\x80\x9c--command\xe2\x80\x9d is deprecated and might be removed in a later version of gnome-terminal.\n# Use \xe2\x80\x9c-- \xe2\x80\x9d to terminate the options and put the command line to execute after it.\nRun Code Online (Sandbox Code Playgroud)要让 bash~/.bashrc在启动时读取并执行,请将其作为交互式 shell 启动:
gnome-terminal --tab -- bash -ic "set-title hey; exec bash"\nRun Code Online (Sandbox Code Playgroud)\n\n现在为什么 \xe2\x80\x99 在非交互式 shell 中获取文件的方法不起作用?我强烈认为你的~/.bashrc开头是这样的:
gnome-terminal --tab -- bash -ic "set-title hey; exec bash"\nRun Code Online (Sandbox Code Playgroud)\n\nreturn如果它所在的 shell 在其任何位置没有 \xe2\x80\x9ci\xe2\x80\x9d $-,即 \xe2\x80\x99s 是一个交互式 shell,那么它就可以不执行任何操作。$-是一个特殊的参数,man bash表示:
\n\n\n
-扩展为调用时指定的当前选项标志、set内置命令或 shell 本身设置的选项标志(例如选项-i)。