MOTDには色がありません。

MOTDには色がありません。

最近ラズベリーパイを購入して使い始めました。私のMOTD(色を含む)を変更した後、カラーコードが実行されるのではなく、生のテキストとして表示されます。

Mac端末でSSH経由でRaspberry Piに接続しています。また、Raspberryコマンドラインから直接試してみました。色をどのように許可しますか?

以下は失敗した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)"

ベストアンサー1

「etc/motd」はプレーンテキストファイルなので、コマンドは実行されず、次のように印刷されます。

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

代わりに、「/etc」に「motd.sh」という新しいファイルを作成し、ここにMOTDと入力してください。これは実行可能なスクリプトですが、実行されません。そのため、「/etc/profile」に移動し、ファイルの末尾に以下を追加します。

bash /etc/motd.sh

接続時にスクリプトが実行され、色が表示されます。

   .~~.   .~~.
  '. \ ' ' / .'
   .~ .~~~..~.
  : .~.'~'.~. :
 ~ (   ) (   ) ~
( : '~'.~.'~' : )
 ~ .~ (   ) ~. ~
  (  : '~' :  ) Raspberry Pi
   '~ .~~~. ~'
       '~'

おすすめ記事