当我登录时,我连接到一个 tmux 会话(如果没有当前会话,则通过 exec'ing tmux,或者如果有,则通过 exec'ing tmux attach)。但是,这意味着我看不到登录消息(/etc/issue、/etc/motd、邮件量等,pam 提供的内容)。有没有办法在 tmux 会话中打印消息?(解决方案应该只依赖于 POSIX shell 语法,即不是 bash/zsh/其他特定于 shell 的)
将这些行添加到您的.bashrc:
declare TMUX
MOTD="/etc/motd"
ISSUE="/etc/issue"
if [ ! -z "$TMUX" ]; then
if [ -f "$MOTD" ]; then
cat "$MOTD"
exit
elif [ -f "$ISSUE" ]; then
cat "$ISSUE"
exit
else
:
fi
fi
Run Code Online (Sandbox Code Playgroud)
这些将检查您是在 tmux 会话内部还是外部。如果在里面,则检查 或/etc/motd是否/etc/issue存在。如果存在,则打印其内容。