While researching more in-depth information about Bash subshells, I ran into an interesting execution that I would like to understand why it works. The execution involves assigning a string to a variable that is then used when man
is called, link to original example. I have already read about why the specific variable LESS
is used in that example (man
has less
as its default pager in many distros), what I do not understand is how a variable assignment followed by a command execution works without any kind of separating metacharacters.
LESS=+/'OPTIONS' man man
opens the man page for the man
command directly under the OPTIONS
section. It works with files opened directly with less
too (which leads me to believe that the LESS
variable is used by less
the same way as doing a regex search within a less
"session"). The LESS
variable is not being exported, it's never saved in the current shell environment (executing echo $LESS
returns nothing) so how is less
capturing that value?
Why does that work, but not something like foo='hello' echo $foo
? This case only works when a command separator (;
) is included between the variable assignment and the command execution. I even tried foo=+'hello' echo $foo
in case =+
did something I was not aware in Bash, but no changes in the output.
Any explanations or reading material are welcome!