top | item 37476429

(no title)

siebenmann | 2 years ago

In this case, one reason to use printenv is that it is an external command, and so it is clearly and unambiguously seeing (and reporting) whatever the Bourne shell would export into the environment for a real command. In this specific case, it appears that set does not report such single-command variables (whether or not they have a value, eg 'FRED=barney set | grep FRED').

(I am the author of the linked-to entry.)

discuss

order

1vuio0pswjnm7|2 years ago

Missing semicolon.

   FRED=barney; set | grep FRED
Also there is no need for grep, nevermind grep -F (fgrep), if using printenv.

   FRED=barney printenv FRED
Without semicolon

   sh -c 'FRED=barney set|grep FRED'

   echo 'FRED=barney set|grep ^FRED'|sh

_TwoFinger|2 years ago

> Missing semicolon.

It's not missing. PP is making a point about "single-command variables."

dcassett|2 years ago

>Missing semicolon.

If you add a semicolon then FRED is no longer a single command variable (it persists)

> on NetBSD, one can do this

Linux also does the expected thing:

$ FRED=barney printenv FRED

barney