The problem isn't with the echo
command, it's with csh's handling of backticks. When you execute
set var = `cat myFile`
the newlines from myfile
are never stored in $var
; they're converted to spaces. I can't think of any way to force a csh variable to include newlines read from a file, though there might be a way to do it.
sh and its derivatives do behave the way you want. For example:
$ x="`printf 'foo
bar'`"
$ echo $x
foo bar
$ echo "$x"
foo
bar
$
The double quotes on the assignment cause the newlines (except for the last one) to be preserved. echo $x
replaces the newlines with spaces, but echo "$x"
preserves them.
Your best bet is to do something other than trying to store the contents of a file in a variable. You said in a comment that you're trying to send an e-mail with the contents of a log file. So feed the contents of the file directly to whatever mail command you're using. I don't have all the details, but it might look something like this:
( echo this ; echo that ; echo the-other ; cat myFile ) | some-mail-command
Obligatory reference: http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…