Portable echo
shell function for POSIX compliant shells. It works exactly the same in all shells.
puts
- Output as is without interpreting escape sequences and options.putsn
-puts
with newline.echo
- Overwrite built-inecho
. Only supported-n
option.
echo -e "\e[31m RED \e[m"
Shell | Output | Shell | Output |
---|---|---|---|
dash | -e RED | mksh | RED |
bash | RED | yash | -e \e[31mRED\e[m |
zsh | RED | posh | -e \e[31mRED\e[m |
ksh | \e[31mRED\e[m | busybox ash | RED |
echo -e "\e[31m RED \e[m"
Shell | Output | Shell | Output |
---|---|---|---|
dash | -e \e[31m RED \e[m | mksh | -e \e[31m RED \e[m |
bash | -e \e[31m RED \e[m | yash | -e \e[31m RED \e[m |
zsh | -e \e[31m RED \e[m | posh | -e \e[31m RED \e[m |
ksh | -e \e[31m RED \e[m | busybox ash | -e \e[31m RED \e[m |
How to output with color.
ESC=$(printf '\033')
echo "${ESC}[31m RED ${ESC}[m"
Shell | Output | Shell | Output |
---|---|---|---|
dash | RED | mksh | RED |
bash | RED | yash | RED |
zsh | RED | posh | RED |
ksh | RED | busybox ash | RED |