Hello -
I have a bash script which does some logging, and I'd like to include the line number of the echo statement that pipes into $LOGGER:
MYPID=$$
MYNAME=`basename $0`
LOGGER="/usr/bin/logger -t $MYNAME[$MYPID]($LINENO) -p daemon.error"
...
echo 'this is an entry into the log file' | $LOGGER
The problem is, $LINENO expands on the "LOGGER" line, and not the "echo" line. I know I could do a function and pass $LINENO to it every time I want to log, I can also escape the parens and call `eval $LOGGER` on every line.
Is there a tight way to do it with a pipe into a single variable, by delaying expansion of the $LINENO var until the echo pipes into $LOGGER?
Thanks!