User Tools

Site Tools


negix:quickonept2

A quick one, pt. 2

In the last post (damn, has it been that long, again?), I wrote something about how to correctly handle tee‘d output and return values in your bash scripts.

If you want to capture all output of your script - as you should, because error messages always pop up in a place you did not expect them - you can use this construct:

#!/bin/bash
 
exec >  >(tee -a logfile.txt)
exec 2> >(tee -a logfile.txt >&2)

This will write all output to the console and logfile.txt.

There is an artifact though, in that the output of the script appears after the new shell prompt. This is somewhat ugly, and gives the impression of a “hanging” script at first glance. If anyone knows a way around that, I would be happy to read about it in the comments (and update this post accordingly).

Hopefully there will be time for a topical rant again some day.

negix/quickonept2.txt · Last modified: 2018/09/10 16:21 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki