To format an output use \e[CODESm
where CODES
is CODE[;CODE]...
.
The following ones are the examples:
- red →
\e[31m
- red and bold →
\e[31;1m
(or\e[1;31m
)
when formatting
PS1
variable, use different syntax:\[\e[31m\]
Echo the white [97] HELLO
word on the blue [104] background:
echo -e '\e[97;104m HELLO \e[0m'
At the end, all the stuff should be reset so that it does not affect further, not ours, output.
In the example above, the code 0
clears any property applied. If it was, for example, the code 21
, it only would clear bold property.
For details, see the last column in the additional properties table.
Color | Code for text color | Code for background color |
---|---|---|
default | 39 | 49 |
black | 30 | 40 |
red | 31 | 41 |
green | 32 | 42 |
yellow | 33 | 43 |
blue | 34 | 44 |
magenta | 35 | 45 |
cyan | 36 | 46 |
white | 97 | 107 |
Color | Code for text color | Code for background color |
---|---|---|
bright gray | 37 | 47 |
dark gray | 90 | 100 |
bright red | 91 | 101 |
bright green | 92 | 102 |
bright yellow | 93 | 103 |
bright blue | 94 | 104 |
bright magenta | 95 | 105 |
bright cyan | 96 | 106 |
Property | Code | Code to reset |
---|---|---|
bold | 1 | 21 |
muted | 2 | 22 |
italic | 3 | 23 |
underline | 4 | 24 |
blinking | 5 | 25 |
reversed | 7 | 27 |
hidden | 8 | 28 |
strike | 9 | 29 |
To reset all the properties, use the code
0
.