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 9007373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:40:20+00:00 2026-06-16T01:40:20+00:00

I am currently working on a shell script where an error may sometimes get

  • 0

I am currently working on a shell script where an error may sometimes get outputted to a file but I need the error moved as it doesn’t mean anything and everything works as normal as long the error isn’t there.

I have a script which has the following:

ftp ftp://$2:$3@$1 << BLOCK > $5
cd "$4"
ls
quit
BLOCK

$5 is the file that the output of the FTP command is written to. So in the file I have the following

total 8
-rw-r--r--  1 root  root  42 Dec 17 14:26 test1.txt
-rw-r--r--  1 root  root   6 Dec 17 14:08 test2.txt

Sometimes I get the error ?Invalid command. so I am using sed to remove the error from the file. I have changed the shell script to the following. Note for testing I have put error within the FTP to ensure I get the error message mentioned above.

ftp ftp://$2:$3@$1 << BLOCK > $5
cd "$4"
ls
error
quit
BLOCK
fileout=$(sed '/?Invalid command./d' $5)
echo $fileout > $5

This is working in the sense that I am removing the error message but it also removing the line breaks so when I look at the file I get the following

total 8 -rw-r--r-- 1 root root 42 Dec 17 14:26 test1.txt -rw-r--r-- 1 root root 6 Dec 17 14:08 test2.txt

How do I retain line breaks?

Thanks for any help you can provide.

  • 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-16T01:40:22+00:00Added an answer on June 16, 2026 at 1:40 am

    You need to quote fileout when you echo i.e. echo "$fileout" > $5, in order to preserve the line breaks.

    BUT, instead of doing that, you should simply use sed to edit the file “in-place”. Then you wouldn’t have to save the output of sed into a variable and then echo it back out again, which is causing the issue.

    Use:

    sed -i '/?Invalid command./d' $5
    

    instead of:

    fileout=$(sed '/?Invalid command./d' $5)
    echo $fileout > $5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a small cute shell script to loop through a specific
Hi i am currently working with mqfte. I use a shell script to invoke
Currently working with converting SQLException error messages into messages that are more useful for
I am currently working on a little backup script from some firebird databases and
I'm writing a Bash script. I need the current working directory to always be
G'day, I'm getting syntax errors when working with a shell script like the following:
I'm currently working on a small script that needs to use gtk.StatusIcon() . For
I'm working on learning Windows PS - but until than I need some help
Currently i have a working PHP edit script, which allows users to edit ads
I'm currently working on a script that logs into another user account using su

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.