Harry McKenzie
Harry McKenzie

Reputation: 218

BASH: How do i cache result of lolcat in variable and print it later?

Is it possible to cache or save the result of lolcat in a variable and print the result out later like so:

RESULT=$(echo mytext | lolcat);
echo $RESULT

The result is missing color formatting.

Upvotes: 1

Views: 994

Answers (1)

Barmar
Barmar

Reputation: 782025

lolcat checks whether the output is going to a terminal. When you use command substitution, the output goes to a pipe, so it doesn't output color change codes.

Use the --force option to override this. And quote the variable to prevent whitespace from being collapsed.

result=$(echo mytext | lolcat --force)
echo "$result"

Upvotes: 3

Related Questions