登录时启动终端并显示消息

登录时启动终端并显示消息

我如何编写一个在登录时执行并启动带有消息的终端的 bash。

伪代码: .bash_login

#!/bin/bash

gnome-terminal
echo "hello user $username";

只是想学习一些 bash 技能。有人能给我指出一个关于这个的好教程吗,或者告诉我怎么做。

答案1

gnome 终端手册显示在打开的终端中执行命令的选项。

   -x, --execute
             Execute  the  remainder  of  the  command  line  inside   the
             terminal.

但问题是,一旦命令完成,终端就会关闭。此主题有一个解决方案:

gnome-terminal -x bash -c "echo 'hello world' ; bash"

这将打开终端并运行 bash shell,然后运行echo然后运行 ​​bash。这本质上与以下脚本相同:

#!/bin/bash

echo 'hello world'
bash

因此gnome-terminal -x script.sh应该运行echo并为您留下一个 bash shell。一旦您退出该 shell,原始 ( bash -c、 或#!/bin/bash) shell 将退出,最后 gnome-terminal 将退出。

您还可以使用每日讯息功能,该功能在每个终端登录后运行。

相关内容