I've written a general purpose logger function in bash called trace() whose 3rd argument and beyond supposed to club and print as text, preserving any embedded newlines. But it doesn't. I'm looking for an effect similar to echo command that does it as intended (tried below). Looks like the club-together thing is to blame (${@:3})?
timeStamp() { echo `date "+%Y-%m-%d %H:%M:%S:%3N %Z"` ;}
trace() {
lineNum=$1
traceType=$2
traceText=${@:3} #Input Parameters 3rd and beyond
#echo -en "[${lineNum}][$(timeStamp)][${traceType}]: ${traceText}"
#printf "[%s][%s][%s]: %s\n" ${lineNum} "$(timeStamp)" ${traceType} "${traceText}"
printf "[${lineNum}][$(timeStamp)][${traceType}]: ${traceText}"
}
Trials/Output:
$ trace $LINENO ERR "This is
a multiline
text
that's supposed to go
upto 5th line"
[342][2017-08-04 00:42:02:062 EDT][ERR]: This is a multiline text that's supposed to go upto 5th line
$ echo "This is a
> multiline text
> that's supposed
> to go
> upto 5th line"
This is a
multiline text
that's supposed
to go
upto 5th line