\c showing in ksh

Hi,

I am having an issue releated to shell-environment on a server.

Let me explain with the example of below script:

#!/bin/ksh
 
echo " enter:\c"
read a
echo $a
 

As I am using ksh the expected output from this script should be 'enter:' (expecting the input for read in same line)
However, the output that I am getting is enter:\c ( which is expecting the input for read in next line).

Please suggest how to solve this issue?:confused:

I cannot use another shell here as the application that I am using has multiple scripts in ksh only.

//Thanks in advance
Mayaank

Which version of ksh are you using? Because with ksh93 it works fine:

$ echo ${.sh.version}
Version M 1993-12-28 s+
$ type echo
echo is a shell builtin
$ echo " enter:\c"
 enter:$
$ which ksh
/usr/bin/ksh
$

Hi Pludi,

I am getting the following:

[root@xxx ~]# su - xxxx
$ ksh
$ 
$ 
$ echo ${.sh.version}
Version M 93s+ 2008-01-31
$ 
$ type echo
echo is a shell builtin
$ echo " enter:\c"
 enter:\c
$ which ksh
/bin/ksh
$

Might be that it's rather got something to do with the way your terminal interprets escape sequences than with the shell itself, as it's even working with ksh88 on HP-UX and pdksh on Linux.

But there's a workaround. Instead of

echo " enter:\c"

use

printf " enter:"

Just to add that the behavior of echo when the first arg does not begin with a -, and none of the arguments contain a \, is defined as system dependent in the ksh93 man pages.

echo [  arg  . . .  ] When the first arg  does not begin with a -, 
and none of the arguments contain a \, then echo prints each of
 its arguments separated by a space and terminated by a new-line.
 Otherwise, the behavior of echo is system dependent and print or
 printf described below should be used. See echo(1) for usage and
 description. 

As already stated, you could (and in my opinion you should) use printf instead of echo.

Other workarounds are:

echo -n enter:
echo -e 'enter:\c'

Thanks for your reply Pludi and Radoulov,

Even when I am trying to run the same on other servers with older ksh versions, it is working for me.

This issue is only occuring on a server on which a newer version of GNU/Linux has been installed.

The workaround that you have suggested might not be able to help me as this issue is affecting multiple scripts in a particular application.

Is there any way to solve this wothout getting on an older linux version?

I don't know other workaround(s).
The usage of echo in shell scripts is discouraged because of the issues you're facing now.

It is affecting awk in some scripts as well... Besides options like \c and \t are not working ...

I am trying to find out if this is only due the OS upgarde which has changed the ksh... or some other reasons...

any help in this is appreciated!

Are you saying that you had something which previously worked and then stopped working after an upgrade?

What was the original Operating System and version?

What is the current Operating System and version?