Search this site

Metadata

Articles

Projects

Presentations

bourne (sh, ksh, bash, zsh, ...) file descriptor fun

Yeah, so having just figured this out now (I'm sure it's in a manpage somewhere) -
You can open file descriptors at will by doing:

exec 3> file_output

The 3 here is the number of the file descriptor, and can be any number really. What this lets you do now is write to that file descriptor:

echo "Hello there" >&3

Now, if you look at the contents of file_output you'll see that it contains "Hello there" - neat?

To close a file descriptor do this:

exec 3>&-

again, where 3 is the number of the file descriptor you want to close.

0 responses to 'bourne (sh, ksh, bash, zsh, ...) file descriptor fun'

Showing last 0 comments... (Click here to view all comments)


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: