bourne (sh, ksh, bash, zsh, ...) file descriptor fun
Posted Thu, 25 Dec 2003
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:
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:
Now, if you look at the contents of
again, where 3 is the number of the file descriptor you want to close.
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.