Monis Monther
asked on
Bash Script Output
I have a bash script that I am working on, each line can have output and error. I am trying to send all output to a file and error to a different file.
My goal is to have a report at the end that I can make use of and in case of problems I would view my error report.
Now the way I am doing this is like this
R=/path/to/reportfile
E=/path/to/errorrepot
And in every line I do this
some syntax > $R 2> $E
I find this too much consuming and not professional. Is there a way to generalize this. I mean is there a way to tell the script to send any output to $R and any error to $E at the begining of the script or do I have to do this in each line.
I am aware that while running the script I can do a > somefile and 2> someotherfile.
I would like to have this inside the script.
Thanks
My goal is to have a report at the end that I can make use of and in case of problems I would view my error report.
Now the way I am doing this is like this
R=/path/to/reportfile
E=/path/to/errorrepot
And in every line I do this
some syntax > $R 2> $E
I find this too much consuming and not professional. Is there a way to generalize this. I mean is there a way to tell the script to send any output to $R and any error to $E at the begining of the script or do I have to do this in each line.
I am aware that while running the script I can do a > somefile and 2> someotherfile.
I would like to have this inside the script.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes, correct.
"exec" is used here for global redirecting of FD 1 (STDOUT) and FD 2 (STDERR) to the respective files.
wmp
"exec" is used here for global redirecting of FD 1 (STDOUT) and FD 2 (STDERR) to the respective files.
wmp
ASKER
Thank a lot.
ASKER
Thanks for the quick responce but can you please explain these to me. I understand that 1 represents STDOUT and 2 represents STDERR.
Does this mean that you are changing the STDOUT and STDERR streams to a file thus redirecting everthing to them.