I did what was suggested here (I just want to use $...$ instead of \texttt{...}, for the sake of experiment):
\documentclass{article}
\catcode`\$=\active
\gdef$#1${\texttt{#1}}
\begin{document}
Hello, $world$!
\immediate\write18{echo $HOME}
\end{document}
The Hello, $world$ line works fine. However, \write18 fails:
! Argument of $ has an extra }.
<inserted text>
\par
l.6 \immediate\write18{echo $HOME}
What is the right way to use $ inside \write18 in this case? I tried \$, no luck.
\catcode\$=\activeafter the write to make it active and\catcode`$=12` (say) before to make it not active – David Carlisle Nov 01 '22 at 19:19\detokenize? – Joseph Wright Nov 01 '22 at 20:32