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

  • SEARCH
  • Home
  • 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 8577889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:15:41+00:00 2026-06-11T20:15:41+00:00

I have a file with several lines. When using cat/more/less [file] in the shell,

  • 0

I have a file with several lines.
When using cat/more/less [file] in the shell,
the content is shown line by line

When doing the following commands:

temp=`cat [file]`
echo $temp

the content is shown in one line.

Is there a way to preserve the line endings when setting to environment variable and then echo it?

Thanks

  • 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-11T20:15:43+00:00Added an answer on June 11, 2026 at 8:15 pm

    Yes:

    temp=`cat [file]`
    echo "$temp"
    

    The magic is in the quotes around $temp; without them, echo gets these arguments:

    echo line1\nline2\nlin3
    

    The shell parsing algorithm will split the command line at white space, so echo sees three arguments. If you quote the variable, echo will see a single argument and the shell parsing won’t touch the whitespace between the quotes.

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

Sidebar

Related Questions

I am using gvim on windows and have a file with several lines that
I have several commands printing text to a file using perl. During these print
I have a text file with several lines in the following format: gatename #outputs
I have several file with the following format: lat,lon,value. I would like to plot
I have a file with several lines of scala code -- imports, list value
I have a text file with 50k+- lines and each line contains data which
I have a file with several column loaded in R. What I want to
I have a CSV file with several entries, and each entry has 2 unix
I have a text file with several different sections. Each section has a header
I have a batch file that runs several python scripts that do table modifications.

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.