Now I am confused, Matthias — where does "TEXNAME" come into it ? In
your example, there was no instance of "TEXNAME" but rather a direct use
of the tilde :
$ lualatex "/home/matt/reports/test~report/report.tex"
Are you now saying that that was not the actual test, but that what you
actually wrote was :
$ lualatex TEXNAME
where "TEXNAME" was an logical name, environment variable, or similar ?
Anyhow, regardless of whether or not the tilde was explicit or implicit,
it will be processed by TeX, and will therefore be subject to expansion.
Consider this from another perspective — if you were to write :
$ tex \expandafter \def \csname my:file\endcsname {Source.tex}\input
\csname my:file\endcsname
you would expect TeX to try to open a file "Source.tex", would you not
? And indeed it does :
This is TeX, Version 3.14159265 (TeX Live 2020/W32TeX) (preloaded
format=tex)
*\end
! I can't find file `Source.tex'.
<to be read again>
\end
<*> \end
(Press Enter to retry, or Control-Z to exit)
Please type another input file name:
Thus /everything/ that follows the imperative "tex" at the command
prompt is interpreted as TeX source, and is not interpreted specially
just because it /might/ be a file name.
/Philip Taylor/