Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7745545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:03:11+00:00 2026-06-01T10:03:11+00:00

This sounds ridiculously easy, and it is with other shells. But I can’t seem

  • 0

This sounds ridiculously easy, and it is with other shells. But I can’t seem to figure out how to get echo to display newlines. For example –

cat myFile

shows the file as it actually exists, which is what I want –

this
is
my
file

whereas my script, which contains the following –

#!/bin/csh
set var = `cat myFile`
echo "$var"

removes all the newlines, which is not what I want –

this is my file

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:03:12+00:00Added an answer on June 1, 2026 at 10:03 am

    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\nbar'`"
    $ 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/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this sounds so easy - but I just can't figure out the syntax. I
This sounds simple, but I just can't get it... I need to display a
This sounds like a stupid question but i can't figure it out for the
This sounds like a trivial question but somehow I can't seem to figure it
This sounds very easy, but i don't get the point. So what's the easiest
This sounds dumb, but I can't get it to work. I think i just
This sounds like a simple enough question, but can't find the answer for the
This sounds like a relatively simple question, but I haven't been able to get
This sounds like a simple one but I can't find the solution anywhere. How
This sounds easy but. I am simply not able to do it. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.