×
UNIX.COM Login
Username:
Password:  
Show Password






👤


Shell Programming and Scripting

BSD, Linux, and UNIX shell scripting Ś Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Newline charachter in Ksh-Linux

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-17-2010
Sanju1236 Sanju1236 is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 23 January 2010, 7:27 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Newline charachter in Ksh-Linux

Hello,

I'm trying to create a muliti value shell variable with newlines inside it, So that I can read the values of that variable individually line by line, but KSH seems to be stripping my variable of newlines in LINUX, but UNIX its working fine.

Here's Example :

Code:
String = "Hello\n""How R U"

echo "$String" |\
   while read _line
   do
     echo $_line
  done

Output in Unix : Hello
Code:
How R U

But In Linux :
Code:
Hello\nHow R U

Please help in solving this.

Thanks!!!!

Last edited by pludi; 01-18-2010 at 01:02 AM.. Reason: code tags, please...
Sponsored Links
    #2  
Old 01-17-2010
Loic Domaigne Loic Domaigne is offline
Registered User
 
Join Date: Aug 2009
Last Activity: 26 December 2011, 4:26 PM EST
Location: Munich (Germany)
Posts: 244
Thanks: 0
Thanked 25 Times in 25 Posts
Hello,

Try:
Code:
echo -e "$String" |\
...

see man 1 echo

Lo´c.
Sponsored Links
    #3  
Old 01-18-2010
Sanju1236 Sanju1236 is offline
Registered User
 
Join Date: Jan 2010
Last Activity: 23 January 2010, 7:27 PM EST
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry , this is not working !!!
    #4  
Old 01-18-2010
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 16 July 2018, 5:46 PM EDT
Location: Amsterdam
Posts: 11,853
Thanks: 546
Thanked 3,469 Times in 3,057 Posts
Try:
Code:
String="Hello\nHow R U"
printf "$String\n" |
while read _line
do
  echo $_line
done

Careful when you assign a value to String: spaces around the =-operator are not allowed..
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Convert special charachter ^C to new line vnag97 Shell Programming and Scripting 2 01-19-2010 10:50 AM
delete line upto the nth occurence of a particular charachter. kashifv Shell Programming and Scripting 12 10-09-2009 06:26 AM
newline character trichyselva UNIX for Dummies Questions & Answers 9 10-31-2008 01:47 PM
newline Gale Gorman Forum Support Area for Unregistered Users & Account Problems 2 05-04-2008 12:23 PM
Counting occurences of specific charachter in a file GMMike UNIX for Dummies Questions & Answers 3 10-13-2004 02:46 PM



All times are GMT -4. The time now is 09:50 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.