-   Linux - Newbie (
-   -   SRDERR and STDOUT (

Batistuta_g_2000 11-01-2011 12:38 PM

So I want to my script to log errors and operations:

OPLOG=$[ 2>&1 1>operations.txt ]
so if I do:


 if [[ -n "$bfilename" ]]; then $OPLOG

it will write to the txt file......but doesn't work, any ideas what I#m doing wrong?

PTrenholme 11-01-2011 01:18 PM

Well, a $[ is, as far as I can recall, not a valid bash construct so. if you're using bash, your OPLOG variable setting would report error that the test function ([ is just an alias for test where you used it.) was improperly invoked. I think what you want is:

OPLOG=' &>operations.txt' (Those are single-quotes, not back-quotes.)

and that, too, would cause an error in your proposed if statement since all OPLOG does is direct output to your log file, and your then clause contains no output generating statement. (Also, you failed to terminate the if with a required fi, but that may be just because you failed to include all of your script.

I'd suggest you look at the info bash documentation, carefully reading the section about the set command (Found in the Modifying Shell Behavior section [4.3] in the Shell Commands [4] group.) with particular attention to the -v and -x values.

All times are GMT -5. The time now is 02:48 PM.