Search code examples
fish

I how can I make echo stop ignoring line breaks in fish


I am doing set catted (cat /home/blue/.ascii/whale.txt) && echo -e $catted

The contents of whale.txt are:

\e[34m\e[5m       .\e[0m
\e[34m\e[5m      ":"\e[0m
\e[36m    ___\e[34m\e[5m:\e[0m\e[36m____     |"\/"|\e[0m
\e[36m  ,'        `.    \  /\e[0m
\e[36m  |  O        \___/  |\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m
\e[97m\e[44m~^~^~^~^~^~^~^~^~^~^~^~^~\e[0m

I need to retain newlines, show the color effects, and show the entire file. How can i do this with fish. Because I have read that you need echo -e "$(cat file.txt)" to show line breaks, but fish doesn't let you use the dollar sign operation.


Solution

  • I'd do

    for line in (cat ~/tmp/whale.txt); echo -e $line; end
    

    fish command substitutions return a list of lines, so with a for loop you're echoing each line.

    Otherwise use sed to inject newlines into the text:

    echo -e (sed 's/$/\\\\n/' ~/tmp/whale.txt)