LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-11-2013, 08:37 AM   #1
bradvan
Member
 
Registered: Mar 2009
Posts: 367

Rep: Reputation: 61
echo append on certain RHEL 6.4 systems not inserting a newline before the text


Anyone have an idea what system setting could be effecting an echo append operation? I have a script that does a simple
Code:
echo "stuff" >> filename
On most servers, it performs as expected and puts in a newline before adding the text. On some of the servers, the newline is not inserted. This is causing me some problems. I'm just not sure what to look at. All the servers are running RHEL 6.4. Any suggestions would be greatly appreciated.
 
Old 10-11-2013, 08:58 AM   #2
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
can you copy/paste some examples of what you mean by not putting text in before adding a new line?
 
Old 10-11-2013, 09:06 AM   #3
bradvan
Member
 
Registered: Mar 2009
Posts: 367

Original Poster
Rep: Reputation: 61
Sure. Example, filename contains:
Code:
this is stuff in the file.
It is really nonsense.
Then on the system with a problem, running:
Code:
echo "crap" >> filename
produces a file looking like:
Code:
this is stuff in the file.
It is really nonsense.crap
while running the same command on a "working" system produces a file like:
Code:
this is stuff in the file.
It is really nonsense.
crap
On the non-working system, the text is appended at the end of the file without inserting a newline first. On what I would call a working system, a newline is inserted first followed by the text. I get the same results whether running on as a non-privileged user and as root.
 
Old 10-11-2013, 10:57 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
The echo command never inserts a newline first unless that happens to be part of the string you are echoing. Typically, the last character in a text file is a newline. If that is missing, you will get the results you are seeing.
 
Old 10-11-2013, 01:33 PM   #5
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
and rknichols beat me to it. tis why i was asking.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Combine two files... without inserting a newline in between them ktrampe Linux - Newbie 8 06-29-2013 09:15 AM
PHP5: echo and print don't display newline abd_bela Programming 4 11-04-2012 10:03 AM
Inserting a block of text into a text file on system boot krptodr Linux - Newbie 5 02-14-2012 07:11 PM
Inserting Multiple Lines (with newline) using sed or awk hal8000b Programming 1 03-08-2009 05:21 PM
A package (or script) to echo "texttext" (append text) to a file on a ftp ? frenchn00b Programming 2 09-03-2008 04:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration