I'm using the following to to tee output of a command into a file:
logs/`basename $0`-`basename $1`.`date +%F--%R\`.log
export LOGFILE=logs/`basename $0`-`basename $1`.`date +%F--%R`.log
export LOGFILE=logs/\`basename $0\`-\`basename $1\`.\`date +%F--%R\`.log
java CMD | tee $LOGFILE
One solution is to define a function in the shell script...
But you almost have it working with the export. If you want to keep going with that, the key is to escape out the $'s so they don't get replaced with their values until you're ready. Then use
eval to re-evaluate it later.
501 ~$ export foo='$bar' 502 ~$ echo $foo $bar 503 ~$ export bar=moo 504 ~$ eval echo $foo moo 505 ~$ export bar=hello 506 ~$ eval echo $foo hello