Results 1 to 4 of 4
Hello -
I have a bash script that uses "logger" to log messages. The way I am using it is:
MYNAME=$0
MYPID=$$
LOGGER="/usr/bin/logger -t $MYNAME[$MYPID]($LINENO) -p daemon.error"
...
echo 'some ...
- 02-17-2009 #1Just Joined!
- Join Date
- Feb 2009
- Posts
- 2
how to delay variable expansion?
Hello -
I have a bash script that uses "logger" to log messages. The way I am using it is:
MYNAME=$0
MYPID=$$
LOGGER="/usr/bin/logger -t $MYNAME[$MYPID]($LINENO) -p daemon.error"
...
echo 'some stuff' | $LOGGER
everything works properly, but the (built-in) $LINENO variable is expanded on the "LOGGER" line instead of the "echo" line.
How would I cause the $LINENO expansion to be delayed, or protected, until the echo command?
Thanks for your help!
- 02-18-2009 #2Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
I think changing LOGGER into a function should solve the problem:
Code:#!/bin/bash MYNAME=$0 MYPID=$$ function LOGGER { /usr/bin/logger -t "$MYNAME[$MYPID]($1)" -p daemon.error $2 } LOGGER $LINENO "some stuff"
- 02-18-2009 #3Just Joined!
- Join Date
- Feb 2009
- Posts
- 2
Thanks secondmouse, yes, that would solve the problem, although it would require an extra parameter on every line I want to log. I was thinking along the lines that some quoting, bracketing, eval or other magic could delay the expansion of the LINENO var (or all vars) until $LOGGER is actually executed. I am actively searching for an answer, I will post a solution when I find one. In the meantime, if you or anyone has any more ideas...
Thanks!
- 02-18-2009 #4Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Scandora,
I am not sure it's worth trying to search for the exact solution that you wanted because if you do
the part echo 'some stuff' does not carry LINENO info that'll be passed to $LOGGER even the line itself implies LINENOCode:echo 'some stuff' | $LOGGER


Reply With Quote