New line character problem with ksh on Redhat Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting New line character problem with ksh on Redhat Linux
# 1  
Old 12-22-2009
New line character problem with ksh on Redhat Linux

Guys,

I would like to discuss the problem I am seeing with echo “\n” statement in Redhat Linux Enterprise 5.3 version. I have a shell script that was written couple of years back for generic UNIX platforms based on ksh and was tested on Solaris 8,9,10 ; AIX 5.3 and Red Hat Enterprise Linux AS release 4. It has used echo with \n option inside all places to print the outputs as standard with ksh (bash was not installed by default that tome on Solaris and AIX) interpreter that was standard that time to get it working on all above platforms.The script is basically a package which has thousands of lines divided into 10- to 15 .sh files.

Now the problem is that when I deploy the script on top of Red Hat Enterprise Linux Server release 5.3, all the echo segments are printing \n as it is, which means its not treating as \n as new line characters. For example

echo "\nOPERATION SUCCESSFUL"

is printing as \nOPERATION SUCCESSFUL.

Its getting printing perfect in Solaris 8,9,10 ; AIX 5.3 and even on Red Hat Enterprise Linux AS release 4.

To replace echo with \n option with printf statement is not feasible as the programs is quite a big. Can anyone please tell me the basic difference Redhat have implemented in ksh version of Redhat Linux Enterprise 5.3?

If anyone has any solution to work echo \n as it is on Redhat Enterprise 5.3, please help me.


Thanks,
Rijesh.
# 2  
Old 12-22-2009
is not version ksh problem:
Code:
man echo:

ECHO(1)                               FSF                              ECHO(1)

NAME
       echo - display a line of text

SYNOPSIS
       echo [OPTION]... [STRING]...

DESCRIPTION
       NOTE:  your shell may have its own version of echo which will supercede
       the version described here. Please refer to your shell's  documentation
       for details about the options it supports.

       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline

       -e     enable interpretation of the backslash-escaped characters listed
              below

       -E     disable interpretation of those sequences in STRINGs

       --help display this help and exit

       --version
              output version information and exit

Code:
$echo "\nNot interpret backslash-escaped\nother"
\nNot interpret backslash-escaped\nother
$echo -e "\nNot interpret backslash-escaped\nother"

Not interpret backslash-escaped
other
$


Last edited by chipcmc; 12-22-2009 at 05:19 AM..
# 3  
Old 12-22-2009
@chipcmc: That's the man page for the program /bin/echo, not for the shell-builtin

@rijeshpp: Are you sure you're running ksh? Check, and if possible post, the output of the following commands:
Code:
rpm -qa | grep ksh
ls -l /bin/sh
echo ${.sh.version}

and, also if possible, the she-bang line of your scripts?
# 4  
Old 12-22-2009
Thanks chipcmc for the reply. echo -e can be used an option work with Redhat Linux and need change in the code. I found echo -e option is not valid in AIX 5.3. I am interested a solution which should work on top all generic UNIX based OS such as Solaris, AIX and Redhat Linux. So echo -a option is not a solution here as my scripts is a generic one for the three OS.

Yes, thanks for pointing out this is a difference in echo, not ksh.

If I need to make the code changes then I could probably replace echo with printf statement.

The point i would like to make is why this change is applicable to Redhat Linux instead of making a standard? what was the intention for such change?

Sorry, the script uses ksh interpreter everywhere.

For example, a block from the code is below.

Code:
case ${helpLevel} in
       0) 
            echo  " "
            echo "This script require three parameters"
		    echo " "
		    echo "Usage: $0 [ {project short name} {corresponding ear filename} {was environment name} ]\n"
		    
		    echo "	-First parameter is the short name of project"
		    echo "	-Second parameter is the EAR file in moduleEAR\{projectName} folder corresponding to Project"
		    echo "	-Third parameter is the name of WAS environment\n"
 		    		    
		    echo "Valid project short name(s)\n"
		    showwasprojectName
            
            echo "\nValid WAS environment name(s)\n"
            showwasenvName
		    exit 1  
       ;;


Last edited by pludi; 12-23-2009 at 01:59 AM.. Reason: code tags, please...
# 5  
Old 12-23-2009
A echo with no parameters would produce \n by default.
# 6  
Old 12-23-2009
You could get by with minimal changes by creating a script that defines your own echo function, and is sourced at the top of every file. That way you'd only need to insert 1 line (quite manageable) and could control the behavior centrally.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Increase command length for ksh shell on Redhat Linux

I have a ksh shell script and i need to pass arguments which are generated by data pulled from a database. When the argument to the shell script is too long (about 4000 charecters) the below is the issue observed. I copy the command which is 4000 charecters long from the logs and paste it... (7 Replies)
Discussion started by: mohtashims
7 Replies

2. Shell Programming and Scripting

Unix-problem of New line character

Hi All, "Please read the below information carefully." i have tried the below code for counting the number of lines present in text file ignoring blank lines #! /bin/bash clear rdCount=0; while read myline do if ; then echo "line is empty" else echo $myline let... (10 Replies)
Discussion started by: aish11
10 Replies

3. Red Hat

redhat linux postfix problem..

hello all, If i send mails using postfix,the mails stored in queue,not delivered to required recipient...can anyone please tell me the solution for this problem... (4 Replies)
Discussion started by: tilakraj
4 Replies

4. Shell Programming and Scripting

problem with KSH script: command line args

Hi I am executing a KSH script by passing command line arguments example: Red Green Dark Red Blue when I am splitting the arguments by using " "(Space) as delimiter But the colour Dark Red is a single parameter. But it is getting splitted in between How to avoid this. Please help Also... (4 Replies)
Discussion started by: hemanth424
4 Replies

5. Red Hat

Problem with configuring host name in Redhat Linux 5

Hi All when I give the command, $ ping <hostname> I get the following error ping: unknown host <hostname> I have checked in the following files, /etc/sysconfig/network /etc/hosts /etc/resolv.conf /etc/nsswitch.conf Every where in these files host name and IP address are given... (2 Replies)
Discussion started by: nagapradeep
2 Replies

6. Red Hat

Rsh problem on redhat linux

Hi, I am trying to do rsh on to a redhat EL 5 machine. It repeatedly asks me for the password and die after sometime. One might think that I am giving the wrong password. But I can do 'ssh' on to that machine with the same password. Can someone tell me what I have been doing wrong? ... (2 Replies)
Discussion started by: eamani_sun
2 Replies

7. Red Hat

redhat linux mail server problem

we are using redhat linux,configured the postfix as mail server and outlook is used as mail client.whenever the user opens outlook it is start downloading all the mails from the server. Example : If a user has 50 mails in the server,whenever he opens the outlook the outlook will start... (0 Replies)
Discussion started by: ramjimh2k3
0 Replies

8. Red Hat

Redhat Linux - Postfix problem

We have a redhat linux el4 and used as a mail server.We configured postfix.all r working fine.we got a problem for a particular user when he tries to open his mailbox and the error is mentioned below: ERROR: Could not complete request. Query: SELECT "INBOX" Reason Given: Internal error... (3 Replies)
Discussion started by: ramjimh2k3
3 Replies

9. UNIX for Dummies Questions & Answers

Display Problem On Linux Redhat 8.0

Hey guys, can anyone please tell me how I can make linux recognize the same video adapter/monitor type that my windows box is using? i'm running linux redhat on virtual PC which enables me to have windows and linux running at the same time. (i can switch back and forth between operating... (4 Replies)
Discussion started by: TRUEST
4 Replies

10. UNIX for Dummies Questions & Answers

Linux Redhat 8.0 Problem

can someone tell me what commands in Linux RedHat 8.0 will give me a graph of whats going on on my system. When Is ay graphs I mean graphs like does produced by perfview of solaris and glance of HP-UX. (3 Replies)
Discussion started by: TRUEST
3 Replies
Login or Register to Ask a Question