I have been using the warning function in bash for some time.
function warn { [ $# -gt 0 ] && printf '%s\n' "$*" >&2 ; }
But I was recently told that I should use one of the following constructs.
function warn { [ $# -gt 0 ] && printf >&2 '%s\n' "$*" ; }
or
function warn { [ $# -gt 0 ] && printf >&2 -- '%s\n' "$*" ; }
I think I understand --
(if the passed parameters contain a dash, it will not be parsed as a parameter).
But what is the difference between redirecting immediately after printf
or at the end?
source
share