Q:

Can you explain eval expression in the default .bashrc

I was looking inside /etc/skel/.bashrc and found this line:
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

I understand what the test -x does, but everything onward with eval is not-understandable. 
Further more, when I run this line in other Linux distros it will cause an error:
#  eval "$(SHELL=/bin/bash lesspipe)"
bash: syntax error near unexpected token `newline'

This is on Ubuntu 14.04 (bash 4.3.11(1)), and the other bash version I tested is 4.3.39(1). 
Can you explain what this line is doing, and why am I getting the above error?

A:

To understand the eval snippet eval "$(SHELL=/bin/sh lesspipe)", we need to break it down:

At first let's check what SHELL=/bin/sh lesspipe returns:
$ SHELL=/bin/sh lesspipe
export LESSOPEN="| /usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s";

As you can see it returns two commands containing variable declarations preceded by export to make them environment variables.
Now another thing, $() is the command substitution syntax that returns exactly what we have seen above i.e. the output of a command, let's check:
$ echo "$(SHELL=/bin/sh lesspipe)"
export LESSOPEN="| /usr/bin/lesspipe %s";
export LESSCLOSE="/usr/bin/lesspipe %s %s";

Ok, what about eval now, so eval will just run the two commands returned by command substitution:
eval "$(SHELL=/bin/sh lesspipe)"

after this the variables LESSOPEN and LESSCLOSE will be environment variables to the shell on which this command is being run.

