# how to escape special chars in \write18?

This is what I'm trying to do (it's just an example, not a real code):

``````\immediate\write18{echo "price: \$5.00" > temp.tex}
\input{temp.tex}
``````

This is what I see in `temp.tex`:

``````price: .00
``````

What is a possible workaround?

• Can this answer be helping? – egreg Oct 7 '12 at 10:31
• It will be easier and cleaner if you put the code in a batch file (or a makefile in Linux parlance) and call it with `\write18`. I usually do this. – kiss my armpit Oct 7 '12 at 10:37

## 1 Answer

"Special" here is special to your shell so it depends which shell you are using. If I execute

``````echo "price: \$5.00"
``````

in bash I get

``````price: .00
``````

So I need to execute

``````echo "price: \\$5.00"
``````

to get

price: \$5.00

so I would need

``````\immediate\write18{echo "price: \string\\$5.00" > temp.tex}
``````

to get a `\$` into the file but since you input it back to TeX you need `\\$` in the file so

``````\immediate\write18{echo "price: \string\\\string\\$5.00" > temp.tex}
``````
• Single quotes can be used instead of double quotes to prevent the shell (Unix) from interpreting `\$5` as shell/environment variable. – Heiko Oberdiek Oct 7 '12 at 10:48
• @HeikoOberdiek yes true, that would be an alternative to the `\string\\ ` although we are both guessing that the OP was in fact using a unix shell. The main point is that you have to escape for your command line shell (with extra backslashes or single quotes and then you have arrange that the file read back in for tex has the correct tex markup, so `\\$` not just `\$` in this case. – David Carlisle Oct 7 '12 at 10:56