Previous: , Up: fd   [Contents][Index]


7.4 Moving file descriptors

Function: mbfl_fd_move SRCFD DSTFD

Move the source file descriptor SRCFD to the destination file descriptor DSTFD. The source file descriptor is closed.

Let’s see how we can use a file for reading and writing with two moved file descriptors:

declare TESTFILE=/path/to/file.ext
declare INFD=3 OUFD=4 DUP_INFD=5 DUP_OUFD=6
declare LINE

mbfl_location_enter
{
    mbfl_fd_open_input_output $INFD "$TESTFILE"
    mbfl_fd_open_output       $OUFD "$TESTFILE"

    mbfl_fd_move $INFD $DUP_INFD
    mbfl_location_handler "mbfl_fd_close ${DUP_INFD}"

    mbfl_fd_move $OUFD $DUP_OUFD
    mbfl_location_handler "mbfl_fd_close ${DUP_OUFD}"

    echo 1234 >&${DUP_OUFD}
    read -u ${DUP_INFD} LINE
}
mbfl_location_leave

echo LINE="$LINE"

Previous: , Up: fd   [Contents][Index]

This document describes version 3.0.0-devel.0 of Marcos Bash Functions Library.