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.

link|improve this question

1  
The escaped version worked on my site (on Linux as well as on SunOS). – bmk May 9 '11 at 8:53
feedback

1 Answer

up vote 1 down vote accepted

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

printf '$' > myfile
link|improve this answer
Erm, why would you choose printf to echo a static string? – jgoldschrafe May 9 '11 at 11:16
1  
@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
feedback

Your Answer

 
or
required, but never shown

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