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"
$f
is expanded before execution. The traps set a variablef
, but since the command you execute isarecord > file1
, the setting of this variable has no effect. – berndbausch Apr 22 '21 at 23:38arecord
runs, no trap can run. – Kamil Maciorowski Apr 23 '21 at 05:41