ko1nksm-shlab / portable-echo.sh

Portable echo shell function for POSIX compliant shells

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Portable echo shell function

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

Functions

  • puts - Output as is without interpreting escape sequences and options.
  • putsn - puts with newline.
  • echo - Overwrite built-in echo. Only supported -n option.

Solved the problem

Problem

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

Portable echo shell function

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

About

Portable echo shell function for POSIX compliant shells

License:Creative Commons Zero v1.0 Universal


Languages

Language:Shell 77.1%Language:Makefile 15.0%Language:Roff 7.9%