Hi forum,
in my bash script I've many lines executing commands with redirection to log files.
...
xyz_cmd 2>&1 > $BASENAME.$LINENO
The trailing part of these lines doesn't look nice and I like to put it into a variable.
The (not working) idea is something like that
REDIRECT='2>&1 > $BASENAME.$LINENO'
...
xyz_cmd $REDIRECT
thanks for suggestions
You could try something like the following
#!/bin/bash
function logAction {
COMMAND=$1
LOGFILE=$2
if [ "x$LOGFILE" == "x" ] ; then
LOGFILE=myLog.log
fi
$COMMAND 2>&1 >> $LOGFILE
}
logAction ls fileList.log
Rather than substituting the redirect, write a logging function
Thanks to both of you.
In both solutions I've to pipe in the $LINENO at the calling point.
I want to avoid that.