以下を考えると:
text="The quick $color fox jumps over the $adjective dog"
変数を変更せずに、値をbashで色付けしてエコー$text
するにはどうすればよいですか?$color
$adjective
例:
$ echo -e --highlight-variables $text
The quick \e[00;31mbrown\e[00m fox jumps over the \e[00;31mlazy\e[00m dog
(実際の色を除く)
しかしその後:
$ echo -e $text
The quick brown fox jumps over the lazy dog
色の変化はありません。
ユーザーがコンソールで確認できるようにテキストを出力できるようにしたいのですless
が、変数をファイルに書き込みますが、ファイルには色情報が含まれていてはなりません。私が実行している実際のコードは次のようになります。
echo -e $text | less
echo "Is this acceptable?"
read accept
if [ "$accept" == "y" ]
then
echo -e $text > output.txt
fi
変数を色で囲むと、エスケープされたテキストがファイルに入れられます。