Edit
Improved version
There are two basically two problems:
\ifstrequal does not expand its arguments
- The content of the environment variable has a trailing whitespace character
at the end, which means
yes will become yes' ', so that the test fails. I could not figure out the reason up to now.
By usage of the xstring package command \StrGobbleRight and \ifdefstring from etoolbox package, it is possible to cope around, hopefully, that it is just one character at the end to be deleted. See the effect as diagnostics in the top of the output document, when \temp and \newtemp macros output -- if the whitespace is removed, the content of the environment variable and the following text should be glued together.
I redefined the getenv command to \newgetenv and used an expanded \edef\temp to make the \ifdefstring command work with the literal yes value.
\documentclass{book}%
\usepackage{etoolbox}%
\usepackage{xstring}%
\usepackage{catchfile}%
\newcommand{\getenv}[2][]{%
\CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{}%
\if\relax\detokenize{#1}\relax\temp\else\let#1\temp\fi}
%\getenv[\INCLUDE]{\string INCLUDE}
\def\newtemp{}%
\newcommand{\newgetenv}[2][]{%
\CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{}%
\StrGobbleRight{\temp}{1}[\newtemp]% Delete the trailing whitespace character
\if\relax\detokenize{#1}\relax\temp\else\edef#1{\newtemp}\fi%
}%
\begin{document}
\newgetenv[\INCLUDE]{INCLUDE}%
%%% Diagnostics:
\temp%
Some Text%
\newtemp%
Some Text%
First paragraph of first file.
Value of the INCLUDE envvar is as follows: \INCLUDE
\ifdefstring{\INCLUDE}{yes}{\input{file2}}{Nothing to do in here}
Last paragraph of first file.
\end{document}
The file file2.tex just contains the line
\textbf{Hello World}

Another version (Thanks to the hint made by H. Oberdiek)
The trailing whitespace(\endlinechar) can be omitted by using \endlinechar=-1\relax as 3rd argument to \CatchFileEdef command. This simplifies the handling of the environment variable macro and the usage of xstring package can be dropped.
\documentclass{book}%
\usepackage{etoolbox}%
\usepackage{catchfile}%
\newcommand{\newgetenv}[2][]{%
\CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{\endlinechar=-1\relax}%
\if\relax\detokenize{#1}\relax\temp\else\edef#1{\temp}\fi%
}%
\begin{document}
\newgetenv[\INCLUDE]{INCLUDE}%
First paragraph of first file.
Value of the INCLUDE envvar is as follows: \INCLUDE
\ifdefstring{\INCLUDE}{yes}{\input{file2}}{Nothing to do in here}
Last paragraph of first file.
\end{document}
I did not update the screenshot, nothing essential has changed in the output.
\expandafter\ifstrequal\expandafter{\INCLUDE}{yes}{...}– egreg Jun 15 '14 at 08:43\endlinechar=-1\relaxin the third argument of\CatchFileEdef. – Heiko Oberdiek Jun 17 '14 at 06:13