Skip to main content
11 events
when toggle format what by license comment
Sep 12, 2021 at 8:10 comment added Chris Davies /dev/null is a sink. You can throw anything and everything you like at it and the data stream is simply discarded. There is never any circumstance when this does not apply. In direct answer to your question, no, there are no circumstances where it's not safe to do this.
Sep 12, 2021 at 8:04 comment added OPPenguin @roaima OK, so tee -a /dev/null is "safe" to use? That makes sense. Are there any circumstances where it's not safe to do this?
Sep 11, 2021 at 7:10 comment added Chris Davies @OstermanA I've added the necessary command structure for you to have output to stdout and optionally to a log file
Sep 11, 2021 at 7:09 history edited Chris Davies CC BY-SA 4.0
Use tee to send output also to stdout
Sep 10, 2021 at 21:20 comment added OPPenguin You are correct that if I just want something as simple as >>${LOG_FILE:-/dev/null} that's trivial, but I want it to always print to screen and conditionally write to file. I'm not sure how to handle that without doing something insane like buffering the log in an array. That seems like a terrible solution, but I'm not seeing any other safe ways to do that.
Sep 10, 2021 at 10:33 history edited Chris Davies CC BY-SA 4.0
Attempt to clarify the two different scenarios
Sep 10, 2021 at 10:31 comment added Chris Davies @ilkkachu there are two situations here. The first one is the easiest - all writes to the log file go to "$LOG_FILE" regardless. The second situation uses the empty/not-empty state of "$LOG_FILE" to identify whether or not certain sections of code should be run at all. In this scenario you can't assign /dev/null to the variable because then it's no longer an empty string so you can't test that
Sep 10, 2021 at 9:30 comment added ilkkachu wouldn't just LOG_FILE=${LOG_FILE:-/dev/null} do for avoiding repeating the default value? :)
Sep 10, 2021 at 9:23 history edited Chris Davies CC BY-SA 4.0
Link to a method for using exec and a file descriptor instead of LOG_FILE
Sep 10, 2021 at 6:58 history edited Chris Davies CC BY-SA 4.0
conditional execution of log file is meaningful
Sep 10, 2021 at 6:50 history answered Chris Davies CC BY-SA 4.0