It seems that using
\immediate\write18{echo "\string#!/bin/bash (version 1)" > \jobname.command}%
outside of a \newcommand works great. However, I want to invoke within a \newcommand:
\newcommand{\CreateBashScript}{%
\immediate\write18{echo "\string#!/bin/bash (version 2)" > \jobname.command}%
}%
but this has an issue with the # (hash / pound symbol).
Notes:
- To reproduce the problem you need to uncomment the line in the definition of
\CreateBashScript.
Code:
\documentclass{article}
\immediate\write18{echo "\string#!/bin/bash (version 1)" > \jobname.command}%
\newcommand{\CreateBashScript}{%
% \immediate\write18{echo "\string#!/bin/bash (version 2)" > \jobname.command}%
}%
\begin{document}
\CreateBashScript
\end{document}
#symbols inside macro definitions' (see e.g. http://tex.stackexchange.com/questions/42463/) – Joseph Wright May 18 '15 at 22:20\stringthe double##issue did not occur to me. Also, even though it is the same answer as the linked question, in this case I am not trying to define a macro via a macro which is where the usual doubling of the#comes up. Or at least that was my understanding. – Peter Grill May 18 '15 at 22:25\stringisn't executed while the command is being defined, and you need##to put a#into the replacement text. – David Carlisle May 18 '15 at 22:27\edef\writehash{\string#}in the preamble and\writehashwhere you want to print a hash mark. – egreg May 18 '15 at 22:35