MOTD 中没有颜色

3 colors ssh terminal motd raspberry-pi

我最近买了一个 Raspberry Pi,并开始玩它。更改我的 MOTD(包括颜色)后,颜色代码将作为原始文本出现而不是执行。

我在 Mac 终端中通过 SSH 连接到我的 Raspberry Pi。我也直接通过 Raspberries 命令行尝试过。我如何允许颜色?

下面是失败的 MOTD 的屏幕截图:

MOTD 颜色错误

我正在编辑的文件是“/etc/motd”。我正在用“纳米”编辑它。

代码如下:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

#!/bin/bash
echo "$(tput setaf 2)
   .~~.   .~~.
  '. \ ' ' / .'$(tput setaf 1)
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) $(tput sgr0)Raspberry Pi$(tput setaf 1)
   '~ .~~~. ~'
       '~'
$(tput sgr0)"
Run Code Online (Sandbox Code Playgroud)

kli*_*ist 5

由于“etc/motd”是纯文本文件,因此不会执行命令,而是按如下方式打印:

#!/bin/bash
echo "$(tput setaf 2)
   .~~.   .~~.
  '. \ ' ' / .'$(tput setaf 1)
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) $(tput sgr0)Raspberry Pi$(tput setaf 1)
   '~ .~~~. ~'
       '~'
$(tput sgr0)"
Run Code Online (Sandbox Code Playgroud)

相反,在“/etc”中创建一个名为“motd.sh”的新文件,并在那里输入 MOTD。这现在是一个可执行脚本,但未执行。所以转到“/etc/profile”并在文件末尾添加:

bash /etc/motd.sh

这将在连接时执行脚本并显示颜色。

   .~~.   .~~.
  '. \ ' ' / .'
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) Raspberry Pi
   '~ .~~~. ~'
       '~'
Run Code Online (Sandbox Code Playgroud)