3

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?

yegor256
  • 12,021

1 Answers1

5

"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}
David Carlisle
  • 757,742
  • Single quotes can be used instead of double quotes to prevent the shell (Unix) from interpreting $5 as shell/environment variable. – Heiko Oberdiek Oct 07 '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 07 '12 at 10:56