Shell – exec < filename - what does this do

io-redirectionshellshell-script

I have found the following code snippet (sh):

    TESTFILE=$TEST_PATH/test.out
    if [ -f $TESTFILE ]
    then
        exec < $TESTFILE
    else
        echo "$TEST_PATH: no test.out file"
    fi

the focus of my question is, what is this line doing? (the rest i understand!)

        exec < $TESTFILE

The file is not executable, nor is another process invoked, and i am having no luck finding what exec does on a plain text file.

Best Answer

From the POSIX description of exec:

exec - execute commands and open, close, or copy file descriptors

In this case, there is no command, so only file descriptors are modified. Normally, redirections you write on the command line affect the command on that line. exec is how you do redirections on the currently executing shell.

Related Question