If you are doing some work on a file descriptor that you expect you'll want to read again, then you can portably do it in the body of a here-document: exec 4<<plus Note that if the file isn't a regular file, you might not be able to seek backwards anyway. I think the only portable solution is to remember the file name and open it as many times as necessary. (There are other utilities that may skip forward but that doesn't help.) There is only one utility that can seek: dd, but it can only seek forward. There's no built-in way to do either in a POSIX shell nor in most sh implementations ( there is one in ksh93). If you want to read back what you wrote, you need to either reopen the file or rewind the file descriptor (i.e. Since each file descriptor has its own position, and the position is set to 0 when opening a file for reading, this command prints the whole file and doesn't affect the script. (There's a single file position, not separate ones for reading and for writing.)Ĭat /proc/$$/fd/3 doesn't do the same thing as cat <&3: it opens the same file on a different descriptor. When you call it, the file position on the file descriptor is where you last left it, namely, at the end of the file. Cat <&3 does exactly what it's supposed to do, namely read from the file until it reaches the end of the file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |