Guest User

Untitled

a guest
Sep 25th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. You can use these ANSI escape codes:
  2.  
  3. Black 0;30 Dark Gray 1;30
  4. Red 0;31 Light Red 1;31
  5. Green 0;32 Light Green 1;32
  6. Brown/Orange 0;33 Yellow 1;33
  7. Blue 0;34 Light Blue 1;34
  8. Purple 0;35 Light Purple 1;35
  9. Cyan 0;36 Light Cyan 1;36
  10. Light Gray 0;37 White 1;37
  11.  
  12. And then use them like this in your script:
  13.  
  14. # .---------- constant part!
  15. # vvvv vvvv-- the code from above
  16. RED='\033[0;31m'
  17. NC='\033[0m' # No Color
  18. printf "I ${RED}love${NC} Stack Overflow\n"
  19.  
  20. which prints love in red.
  21.  
  22. From @james-lim's comment, if you are using the echo command, be sure to use the -e flag to allow backslash escapes.
  23.  
  24. # Continued from above example
  25. echo -e "I ${RED}love${NC} Stack Overflow"
  26.  
  27. (don't add "\n" when using echo unless you want to add additional empty line)
Add Comment
Please, Sign In to add comment