Unix/Linux Go Back    


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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-17-2010   -   Original Discussion by Sanju1236
Sanju1236's Unix or Linux Image
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 02:02 AM.. Reason: code tags, please...
Sponsored Links
    #2  
Old Unix and Linux 01-18-2010   -   Original Discussion by Sanju1236
Loic Domaigne's Unix or Linux Image
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 Unix and Linux 01-18-2010   -   Original Discussion by Sanju1236
Sanju1236's Unix or Linux Image
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 Unix and Linux 01-18-2010   -   Original Discussion by Sanju1236
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is online now Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 16 December 2017, 4:10 AM EST
Location: Amsterdam
Posts: 11,658
Thanks: 520
Thanked 3,386 Times in 2,985 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
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 11:50 AM
delete line upto the nth occurence of a particular charachter. kashifv Shell Programming and Scripting 12 10-09-2009 07:26 AM
newline character trichyselva UNIX for Dummies Questions & Answers 9 10-31-2008 02:47 PM
newline Gale Gorman Forum Support Area for Unregistered Users & Account Problems 2 05-04-2008 01:23 PM
Counting occurences of specific charachter in a file GMMike UNIX for Dummies Questions & Answers 3 10-13-2004 03:46 PM



All times are GMT -4. The time now is 05:10 AM.