I stumbled upon this question regarding accessing environment variables from latex and have problems properly escaping variables containing special tex symbols (e.g. LANG=en_US.UTF-8)
My closest attempt can be found below but it still replaces the underscore with a weird dot:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\getenv}{om}
{
\sys_get_shell:nnN{ kpsewhich ~ --var-value ~ #2 }{}#1
}
\begin{document}
\getenv[\LANG]{LANG}
\tl_to_str:N\LANG
\end{document}
Furthermore this also does not correctly handle other special symbols like @

\usepackage[T1]{fontenc}. This is a duplicate. Your definition is wrong, as I explained in a comment to your answer in the linked thread. What do you mean by the last paragraph? – egreg Jun 03 '20 at 21:19AB='@'in the shell and then\getenv[\AB]{AB}\ABprints the expected@. – egreg Jun 03 '20 at 21:25\showyour definition worked and adding fontspec whilst using lualatex resolved the weird dot problem. I am so accustomed to lualatex that I forgot to add it whilst experimenting with the code. Thank you – Septatrix Jun 03 '20 at 21:31