Home

Awesome

Portable echo shell function

Portable echo shell function for POSIX compliant shells. It works exactly the same in all shells.

Functions

Solved the problem

Problem

echo -e "\e[31m RED \e[m"
ShellOutputShellOutput
dash-e <font color="red">RED</font>mksh<font color="red">RED</font>
bash<font color="red">RED</font>yash-e \e[31mRED\e[m
zsh<font color="red">RED</font>posh-e \e[31mRED\e[m
ksh\e[31mRED\e[mbusybox ash<font color="red">RED</font>

Portable echo shell function

echo -e "\e[31m RED \e[m"
ShellOutputShellOutput
dash-e \e[31m RED \e[mmksh-e \e[31m RED \e[m
bash-e \e[31m RED \e[myash-e \e[31m RED \e[m
zsh-e \e[31m RED \e[mposh-e \e[31m RED \e[m
ksh-e \e[31m RED \e[mbusybox ash-e \e[31m RED \e[m

How to output with color.

ESC=$(printf '\033')
echo "${ESC}[31m RED ${ESC}[m"
ShellOutputShellOutput
dash<font color="red">RED</font>mksh<font color="red">RED</font>
bash<font color="red">RED</font>yash<font color="red">RED</font>
zsh<font color="red">RED</font>posh<font color="red">RED</font>
ksh<font color="red">RED</font>busybox ash<font color="red">RED</font>