This question is a followup to this thread in which @egreg provided a command \getenv to access a system environment variable. In response to my comment, he suggested a way to expand his script so that it would deal with the possibility that the environment variable was not defined.
I believe I've followed his suggestion in the script below, and
expected the \getenv command in the body of the email to return UNDEFINED, but it returns empty. Could you please explain how to get it to do so? Thanks!
\documentclass{article}
\usepackage{catchfile}
\newcommand{\getenv}[2][]{%
\CatchFileEdef{\temp}{"|kpsewhich --var-value #2"}{}%
\ifx\temp\empty\def\temp{UNDEFINED}\fi
\if\relax\detokenize{#1}\relax\temp\else\let#1\temp\fi}
\begin{document}
test \getenv{NOT_DEFINED}
\end{document}
