I'm currently trying to curl some raw text and have it displayed with interpreted ANSI colours in the Terminal.

Currently, when I run curl http://example.com/test.txt (not the actual URL), it simply returns:


This is not what I am looking for; what I expected to be returned is what I see when I run echo -e "\033[0;31mTEST\033[0m", which returns TEST, coloured in red.

My question is: is there a way of making curl interpret ANSI colour codes in order to have the colours properly displayed in the Terminal as you would expect when using echo -e?

  • 1
    Just out of curiosity, why use curl here? I mean, it's a tool for the HTTP protocol, and you're dealing with ANSI escape codes for the terminal. I feel like I'm missing a connection here. – Haxiel Feb 11 '19 at 16:26
  • 1
    @Haxiel Interestingly enough, I'm trying to add a sort of easter egg to a poster at my college, where echo -e "$(curl -s http://example.com/test.txt)" is in small print, and if they find the message they win a prize. – Rocco Feb 11 '19 at 17:08

Not sure if this is the best way to do it, but using command substitution seems to work fine (even if it is a bit bulky):

echo -e "$(curl -s http://example.com/test.txt)"

Hopefully that's helpful for people in the future. Note that you can use curl -sL if you are dealing with a shortened URL.


Are you sure you are putting the raw escape sequences in the txt file? I tried it with curl-7.52.1 using both netcat and apache, and in both cases curl splatted out the escape sequence correctly to make the word colored red on my terminal.

Try this,

echo $'\e[0;31mTEST\e[0m' | nc -l -p 8080 -q0
curl localhost:8080

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.