How to write to a named file descriptor in Bash? How to write to a named file descriptor in Bash? bash bash

How to write to a named file descriptor in Bash?


The string inside the braces is just the name of a variable the shell will set for you, whose value is the file descriptor the shell allocates. The braces are not part of the name. In order to use it, just expand the variable in the proper context.

$ exec {out}>out$ echo foobar >&$out$ cat outfoobar

In your example, the file {out} was created by

echo >&{out}

not the initial exec whose redirection created the file out stored the allocated file descriptor in the variable out.


echo test >&${out}

If you do exec {out}>out, then $out gives you the fd number.