Why doesn't \c work in sh/ksh echo on Suns?

Guy Harris guy at gorodish.Sun.COM
Fri Aug 5 04:25:51 AEST 1988


> On the Sun 3/50's here at Ohio State University sh and ksh don't
> work correctly when echo is given a string that terminates with
> a \c.  The output from:
> 
> 	echo "Enter terminal type: \c"
> 
> should be the line "Enter terminal type: " but not terminated with
> a new line (and with the "'s removed).  This works in every other
> sh and ksh echo I've used.  Anyone know what the problem is?

I can't speak for "ksh"; however, you've presumably not used a Version 7 UNIX
shell, because "\c" doesn't do that in the V7 shell - you have to say

	echo -n "Enter terminal type: "

The SunOS shell, starting in Release 3.2, can be made to support either form of
echo.  It pretends that "echo" is a regular command, rather than a built-in,
that would reside either in "/bin" or in "/usr/5bin"; if it would have found
the one in "/bin", it gives V7-style behavior with "-n" but no backslash
escapes, and if it would have found the one in "/usr/5bin", it gives S5-style
behavior with no "-n" but with backslash escapes including "\c".  (Thanks and a
tip of the Hatlo hat to Dave Korn for this trick.  I don't know whether your
"ksh" has this or not, since I don't know which "ksh" you have.)

You can have your script set $PATH (shell scripts should always do that anyway,
so they don't get surprised by non-standard $PATHs); however, this means you'd
get the S5-environment versions of other commands as well, which may or may not
be what you want.



More information about the Comp.unix.questions mailing list