Skip to content

Instantly share code, notes, and snippets.

@rawiriblundell
Last active October 8, 2020 20:59
Show Gist options
  • Select an option

  • Save rawiriblundell/d8c51fd7aadf8adcd8af4068005a46f8 to your computer and use it in GitHub Desktop.

Select an option

Save rawiriblundell/d8c51fd7aadf8adcd8af4068005a46f8 to your computer and use it in GitHub Desktop.
Attempt to write a portable-ish echo shell function
echo() {
case "${1}" in
(-e)
case "${2}" in
(-n|--end) shift 2; printf -- '%b' "${*}" ;;
(*) shift; printf -- '%b\n' "${*}" ;;
esac
;;
(-E)
case "${2}" in
(-n|--end) shift 2; printf -- '%s' "${*}" ;;
(*) shift; printf -- '%s\n' "${*}" ;;
esac
;;
(-j) shift; printf -- '{"%s": "%s"}\n' "${1}" "${2}" ;;
(-n|--end)
case "${2}" in
(-e) shift 2; printf -- '%b' "${*}" ;;
(-E) shift 2; printf -- '%s' "${*}" ;;
(*) shift; printf -- '%s' "${*}" ;;
esac
;;
(-en|-ne) shift; printf -- '%b' "${*}" ;;
(-En|-nE) shift; printf -- '%s' "${*}" ;;
(*) printf -- '%s\n' "${*}" ;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment