Skip to content

ko1nksm-shlab/portable-echo.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published