ksh93 newline character problem


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers ksh93 newline character problem
# 1  
Old 06-07-2010
ksh93 newline character problem

Hi ,
I am working on Linux, with ksh93 installed.

The following statement
echo \\n

just prints

\n on this shell.

However on pdksh
echo \\n gives a blank new line as a output.

What is the correct way of printing a new line character on the ksh93?
# 2  
Old 06-07-2010
Hi,

You could try:
Code:
echo -e \\n

However, the behaviour of echo is system dependent, so in general it would be better to use
Code:
printf "\n\n"

instead...
# 3  
Old 06-07-2010
Thanks..
I have another question .. I am trying to assign this value to another variable:
${fetched_value} contains the string with \n

So following prints the value correctly
Code:
echo -e   ${fetched_value} " My manipulated value "

SYS_P8708 SYS_P8564 SYS_P8500 60
SYS_P8709 SYS_P8565 SYS_P8501 61


however when I try to manipulate this variable to something like:
Code:
fetched_value=`echo -e ${fetched_value}`

i get the following output
Code:
SYS_P8708 SYS_P8564 SYS_P8500 60 SYS_P8709 SYS_P8565 SYS_P8501 61

What am I doing wrong here?

Last edited by Franklin52; 06-08-2010 at 05:26 AM.. Reason: Please use code tags!
# 4  
Old 06-08-2010
Hi, what exactly is you input and your output, what did you try, and what is your desired output?
# 5  
Old 06-08-2010
Quote:
Originally Posted by neeto
"echo \\n" just prints "\n" on this shell.
This should be regarded as a bug in pdksh, the behavior of ksh93 is absolutely definitely correct.

You probably know that "\" is used to escape characters with a special meaning to the shell. For instance "$var" would be parsed the following way: the shell sees "$", which means "take the word after that and look for a variable with that name ("var"), then replace the "$" and the word following it with the contents of this variable". Because there is no way to literally use a "$" this way we can use "\$" to tell the shell not to regard this special behavior of "$" and treat it like a normal character.

Example:

Code:
var="abcde"
echo $var           # output: "abcde"
echo \$var          # output: "$var"

For the same reason we need to escape the backslash itself, because it also has a special meaning - to escape other characters. Therefore: to literally write a backslash we have to precede it by a - backslash!

Look at your statement now in light of this explanation, the reason why the output has to be "\n" should be clear by now.

Quote:
Originally Posted by neeto
I have another question
Moderator's Comments:
Mod Comment Please open another thread for this. We want our threads to deal with only one problem at a time to make our database of problems already dealt with as clear as possible. Thanks.


I hope this helps.

bakunin
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to remove newline character if it is the only character in the entire file.?

I have a file which comes every day and the file data look's as below. Vi abc.txt a|b|c|d\n a|g|h|j\n Some times we receive the file with only a new line character in the file like vi abc.txt \n (8 Replies)
Discussion started by: rak Kundra
8 Replies

2. UNIX for Advanced & Expert Users

Ksh93 on Linux compatible with ksh93 on AIX

Hi Experts, I have several shell scripts that have been developed on a Linux box for korn ksh93. If we want to run this software on an AIX 6.1 box that runs ksh88 by default can we just change the she-bang line to reference /bin/ksh93 which ships with AIX as its "enhanced shell" to ensure... (6 Replies)
Discussion started by: Keith Turley
6 Replies

3. Shell Programming and Scripting

Remove last newline character..

Hi all.. I have a text file which looks like below: abcd efgh ijkl (blank space) I need to remove only the last (blank space) from the file. When I try wc -l the file name,the number of lines coming is 3 only, however blank space is there in the file. I have tried options like... (14 Replies)
Discussion started by: Sathya83aa
14 Replies

4. Shell Programming and Scripting

replacing by newline character

I have a file (pema)with a single long record which i have to break up into multiple lines Input s1aaaaaaaaaaaaaaaaaaaaaaas1bbbbbbbbbbs1cccccccccc Output s1aaaaaaaaaaaaaaaaaaaaaaa s1bbbbbbbbbb s1cccccccccc m planning to do it by replacing s1 by \ns1 \n is the new line character i... (5 Replies)
Discussion started by: pema.yozer
5 Replies

5. UNIX for Dummies Questions & Answers

newline character in a variable

variable="unix\nlinux" echo $variable expected output: unix linux :wall: can i do that ?? thanks in advance!! (3 Replies)
Discussion started by: sathish92
3 Replies

6. Shell Programming and Scripting

Why SED can't see the last newline character?

Removed. My question does not make sense. and SED does see the last newline character. But I still have a question: How to remove the last newline character(the newline character at the end of last line) using SED? ---------- Post updated 05-01-11 at 10:51 AM ---------- Previous update was... (7 Replies)
Discussion started by: kevintse
7 Replies

7. Shell Programming and Scripting

Read Embedded Newline characters with read (builtin) in KSH93

Hi Guys, Happy New Year to you all! I have a requirement to read an embedded new-line using KSH's read builtin. Here is what I am trying to do: run_sql "select guestid, address, email from guest" | while read id addr email do ## Biz logic goes here done I can take care of any... (6 Replies)
Discussion started by: a_programmer
6 Replies

8. UNIX for Dummies Questions & Answers

echo without newline character

hi, I have a for loop where in I write some file name to another file. I want to write all the filenames to another without any newlines. how can i avoid getting new lines with echo? Thanks, Srilaxmi (2 Replies)
Discussion started by: srilaxmi
2 Replies

9. UNIX for Dummies Questions & Answers

newline character

hi, I want to print the below lines "Message from bac logistics The Confirmation File has not been received." When i give like this in the code "Message from bac logistics\n The Confirmation File has not been received." It is giving only Message from bac logistics\n The... (9 Replies)
Discussion started by: trichyselva
9 Replies

10. UNIX for Dummies Questions & Answers

How can I replace newline character?

Hi, I am trying to write a script to prepare some text for use as web content. What is happening is that all the newlines in the textfile are ignored, so I want to be able to replace/add a few characters so that for a file containg: This is line 1. This is line two. This is line four.... (1 Reply)
Discussion started by: ghoti
1 Replies
Login or Register to Ask a Question