Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

This is what I see in temp.tex:

price: .00

What is a possible workaround?

share|improve this question
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. –  Please don't touch Oct 7 '12 at 10:37

1 Answer 1

up vote 3 down vote accepted

"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}
share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.