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.
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
$
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...
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.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)