How can I use variables in the exec command?
If I do the command below, it works:
$ exec 3>&1
$ var=3; exec $var>&1
bash: exec: 3: not found
Instead of making the file descriptor configurable, let
bash itself allocate an unused file descriptor for you.
You can then use
$var later in other redirections.
printf '%s' "Some message" >&$var