0

How can you change where output of a command goes throughout its lifetime?

Below I'd hoped arecord's output would start going to file2 when the script received a USR2 signal but it keeps to file1.

#!/usr/bin/env sh
f=file1
trap f=file1 USR1
trap f=file2 USR2
arecord > "$f"
aaa
  • 207
  • 1
  • 11
  • Does this answer your question? [How to change the output file of a pipe without stopping](https://unix.stackexchange.com/questions/644659/how-to-change-the-output-file-of-a-pipe-without-stopping) – Kamil Maciorowski Apr 22 '21 at 21:55
  • 1
    You script doesn't work as you expect because `$f` is expanded before execution. The traps set a variable `f`, but since the command you execute is `arecord > file1`, the setting of this variable has no effect. – berndbausch Apr 22 '21 at 23:38
  • 1
    Additionally when `arecord` runs, [no trap can run](https://unix.stackexchange.com/a/282631/108618). – Kamil Maciorowski Apr 23 '21 at 05:41

0 Answers0