Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to echo/printf a dollar sign into a file - but echo $ > myfile or such does not work (not surprising).

I tried escaping it like echo \$ > myfile but it is also not working.

What is the correct way to perform it?

I'm working with TCSH on SunOs.

share|improve this question
The escaped version worked on my site (on Linux as well as on SunOS). – bmk May 9 '11 at 8:53
up vote 3 down vote accepted

You can use printf and single quotes to avoid variable expansion:

printf '$' > myfile
share|improve this answer
Erm, why would you choose printf to echo a static string? – jgoldschrafe May 9 '11 at 11:16
@jgoldschrafe: Because I'm sure the Solaris printf command will be used in that case so I can avoid whatever oddity tcsh echo builtin might introduce. – jlliagre May 9 '11 at 12:15

From this link, you can use the \x24 method, where 24 is the hex for the dollar sign. Just that this structure doesn't work 100% with string using the double quote, so you probably want to use a single quote. So this statement

echo "Foo "$'\x24'" bar" >> somefile

will create somefile with the content

Foo $ bar
share|improve this answer

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.