0
LOCK_FD=200 LOCK_FILE=/tmp/lock-file exec ${LOCK_FD}>${LOCK_FILE} 

I get an error

exec: 200 not found 

This however works

LOCK_FD=200 LOCK_FILE=/tmp/lock-file eval "exec ${LOCK_FD}>${LOCK_FILE}" 

Any idea why?

    1 Answer 1

    2

    Methinks that's because redirection is performed before variable expansion. man bash is not quite clear which is done first:

    REDIRECTION Before a command is executed, its input and output may be redirected . . .

    EXPANSION Expansion is performed on the command line after it has been split into words.

    With the redirection done and removed, exec tries to execute 200 which doesn't exist, and thus the error msg.

    1
    • ok thank you, I guess that explanation works.CommentedOct 19, 2018 at 1:08

    You must log in to answer this question.

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.