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.

is not version ksh problem:

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


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

Not interpret backslash-escaped
other
$

@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:

rpm -qa | grep ksh
ls -l /bin/sh
echo ${.sh.version}

and, also if possible, the she-bang line of your scripts?

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.

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  
       ;;

A echo with no parameters would produce \n by default.

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.