The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
deleting newline characters but not the "true" \n character caddyjoe77 Shell Programming and Scripting 1 08-15-2007 07:21 PM
remove trailing newline characters shweta_d Shell Programming and Scripting 7 06-05-2007 06:29 AM
Formatting a text file based on newline and delimiter characters ntekupal Shell Programming and Scripting 5 05-11-2007 12:33 PM
echo command result umen UNIX for Dummies Questions & Answers 2 11-10-2005 04:39 AM
FTP command result nymus7 IP Networking 1 08-08-2005 02:01 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-02-2008
Registered User
 

Join Date: Dec 2007
Posts: 14
how to keep newline characters in command execution result?

I found that when I used a variable to receive the result from a command execution, the newline characters were removed from the variable.

For example, I ran

$ ret=`ls -l`
$ echo $ret

Then, I saw:
total 40 -rw-r--r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk -rw-rw-r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk1

But the output I expected is:
total 40
-rw-r--r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk
-rw-rw-r-- 1 testtrunk testtrunk 0 Dec 13 11:13 pk1

So, the question is, how to keep the newline characters in the variable that receives the command result?

Thanks.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-02-2008
drl's Avatar
drl drl is offline
Registered User
 

Join Date: Apr 2007
Location: Saint Paul, MN USA / BSD, CentOS, Debian, OS X, Solaris
Posts: 496
Hi.

Use double-quotes around the variable in the echo ... cheers, drl
Reply With Quote
  #3 (permalink)  
Old 01-02-2008
Registered User
 

Join Date: Dec 2007
Posts: 14
Quote:
Originally Posted by drl View Post
Hi.

Use double-quotes around the variable in the echo ... cheers, drl
drl, thanks!
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:16 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0