Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 587
Zhro Avatar asked Jun 23 '13 13:06

Zhro


1 Answers

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
like image 62
glenn jackman Avatar answered Nov 05 '22 17:11

glenn jackman