If I type the following command in a bash shell:
STUFF=Blah env | grep STUFF
I am confused why it would return STUFF=Blah as I would expect to get an empty output.
The reason I am confused is because (as I understand) STUFF=Blah sets STUFF as a shell variable, but the env command returns all environment variables.
But in the above STUFF=Blah seems to be set as an environment variable. Where am I going wrong in my understanding?
From the bash man page (ENVIRONMENT section):
The environment for any simple command or function may be augmented temporarily by prefixing it with parameter assignments, as described above in PARAMETERS. These assignment statements affect only the environment seen by that command.
This means that your understanding of the STUFF=Blah at the start of a command is incorrect. When using before a command, it sets an environment variable for the command being run. When used by itself (just STUFF=Blah without any further command), then it sets a local shell variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With