Skip to content
zeta709 edited this page Jan 24, 2022 · 2 revisions

echo

The examples below are from [1].

echo() (
    IFS=" "
    printf '%s\n' "$*"
)

echo_n() (
    IFS=" "
    printf '%s' "$*"
)

echo_e() (
    IFS=" "
    printf '%b\n' "$*"
)

You may use local keyword instead of using a subshell.

References

  1. https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo
  2. https://stackoverflow.com/questions/18597697/posix-compliant-way-to-scope-variables-to-a-function-in-a-shell

Clone this wiki locally