The thread-sanitizer library gives the first case as how to get their library (used within myprogram) to read the file given in options.  I read it, a

What is the difference between an inline variable assignment and a regular one in Bash?

submited by
Style Pass
2021-06-25 02:00:07

The thread-sanitizer library gives the first case as how to get their library (used within myprogram) to read the file given in options. I read it, and assumed it was supposed to be two separate lines, so ran it as the second case.

The library doesn't use the file in the second case, where the environment variable and the program execution are on separate lines.

Bonus question: How does the first case even run without error? Shouldn't there have to be a ; or && between them? The answer to this question likely answers my first...

The format VAR=value command sets the variable VAR to have the value value in the environment of the command command. The spec section covering this is the Simple Commands. Specifically:

Otherwise, the variable assignments shall be exported for the execution environment of the command and shall not affect the current execution environment except as a side-effect of the expansions performed in step 4.

The format VAR=value; command sets the shell variable VAR in the current shell and then runs command as a child process. The child process doesn't know anything about the variables set in the shell process.

Leave a Comment