QuestionAnswer224edited May 23, 2017 at 12:18Rather than using archaic terminal codes, may I suggest the following alternative. Not only does it provide more readable code, but it also allows you to keep the color information separate from the format specifiers just as you originally intended.
WEBprintf ${danger:-'%b'}'\n' "This will be red and would not break if color is unavailable"; Or if you want to compose a message over multiple lines, just leave out the '\n' printf $info "This is "; printf $info "blue!"; printf '\n' Reviews: 1
Reviews: 1
DA:78PA:55MOZ Rank:61
bash script - output in color using printf - Stack Overflow
WEBSpecifically, you tell the terminal to start displaying red characters by print the sequence \e[31m (that's 5 characters: ASCII 27 (escape), [, 3, 1, and m ). To tell the terminal to use … Reviews: 2
Reviews: 2
DA:78PA:2MOZ Rank:91
How to use printf and %s when there are color codes?
WEBMay 25, 2015 · Use printf "..%s.." "$foo". So I tried changing it to. printf "%s Error - Function: %s, Line: %s \n", "$fail_color", "$function", "$line_number". but now the output … Reviews: 3
WEBDec 27, 2016 · You can make your BASH script more pretty, by colorizing its output. Use ANSI escape sequences to set text properties like foreground and background colors. … Reviews: 12
WEBFeb 24, 2022 · The bash printf command is a tool used for creating formatted output. It is a shell built-in, similar to the printf() function in C / C++, Java, PHP, and other programming languages. The command …
DA:12PA:47MOZ Rank:45
Bash printf - How to Print a Variable in Bash - phoenixNAP
WEBFeb 26, 2023 · The printf command is used to format and print text in Bash. It allows users to specify the format of the output, including the width of the output, the number of …
WEB317. I spend most of my time working in Unix environments and using terminal emulators. I try to use color on the command line, because color makes the output more useful and intuitive. What options exist to add …