Skip to content

Instantly share code, notes, and snippets.

@yosske
Created June 21, 2016 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosske/4cfbcbab63f8f3dd9f24b38f4acd7757 to your computer and use it in GitHub Desktop.
Save yosske/4cfbcbab63f8f3dd9f24b38f4acd7757 to your computer and use it in GitHub Desktop.
Like echo, but in the --color that grep uses when that option is given
#!/bin/sh
#handle no input - just fire echo and exit
if [ "$#" -eq 0 ]; then
echo
exit
fi
#concat params like echo does
str="$1"
shift
for var in "$@"
do
str=$str" "$var
done
#use a match all grep to with --color to color the output
echo "$str" | grep --color -o ".*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment