LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   Can I redirect script output to a file without ">> $LOGFILE" at the end of each line (http://www.linuxquestions.org/questions/linux-general-1/can-i-redirect-script-output-to-a-file-without-%24logfile-at-the-end-of-each-line-127184/)

davee 12-19-2003 05:35 AM

Can I redirect script output to a file without ">> $LOGFILE" at the end of each line
 
To stop me having to do...

export OUTFILE=/home/user/logs
echo "Start script" >> $OUTFILE
echo "Blah blah " >> $OUTFILE
run command -a -h >> $OUTFILE
do this and that >> $OUTFILE
echo "Stop Script" >> $OUTFILE

Dave...

iainr 12-19-2003 06:01 AM

Two ways round this.

1. Put the chunk of code in curly brackets[code]{
echo "Start script"
echo "Blah blah "
run command -a -h
do this and that
echo "Stop Script"
} >> $OUTFILE

2. Use the exec command to redirect output to the file automatically (I have to say I haven't done this with Linux/Bash so read the man page for this one).


All times are GMT -5. The time now is 04:57 PM.