A friend of mine had the following idea which I’m now using. I’ve only tested it on Windows XP and OS X where it works fine. A bit flimsy on testing, admittedly, but in principle it should work fine almost anywhere else.
\newif\ifwindows
\immediate\write18{echo $SHELL > \jobname.os}
\newread\@whichos
\immediate\openin\@whichos\jobname.os
\read\@whichos to \@whichosshell
\ifthenelse{\equal{\@whichosshell}{$SHELL }}
{\windowstrue}
{\windowsfalse}
\closein\@whichos
\ifwindows
\typeout{System detected: Windows}
\newcommand\DeleteFile[1]{\immediate\write18{del #1}}
\else
\typeout{System detected: Unix-like}
\newcommand\DeleteFile[1]{\immediate\write18{rm #1}}
\fi
% Cleanup.
\DeleteFile{\jobname.os}
The key here is that Windows won’t expand the $SHELL
environment variable (any other variable would have done, really) so it will write the string $SHELL
to the file literally.