Zhro Zhro - 1 year ago 89
Bash Question

Write to file descriptor 3 without writing to disk?

Is there a way to interact with file descriptors without having to open a file on disk?

This won't work without a file first being assigned to fd3:

echo a >&3

Answer Source

Depends on what you want to do. Suppose you want to write strings at your leisure and print them reversed. set up a file descriptor redirecting into a process substitution waiting for stdin:

$ exec 3> >(rev)
$ echo hello world >&3
dlrow olleh

When you're done with it, you can close the file descriptor

$ exec 3>&-
$ echo hello world >&3
bash: 3: Bad file descriptor
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download