It is currently Thu, 20 Jan 2022 05:02:28 GMT



 
Author Message
 echo -n not working in /bin/sh
man -s 1 echo:

     sh's  echo and /usr/bin/echo only have a  -n  option
     if  the  SYSV3  environment variable is set (see ENVIRONMENT
     below).

Apparently, that's a lie:

klischat@butterfly:~ > uname -a
SunOS butterfly 5.8 Generic_117350-08 sun4m sparc
klischat@butterfly:~ > /bin/sh
\u@\h:\w > SYSV3=1; export SYSV3
\u@\h:\w > echo -n foobar
-n foobar
\u@\h:\w >

Olaf



 Sun, 20 May 2007 04:19:16 GMT   
 echo -n not working in /bin/sh

Well, at least it's fixed in Solaris 10 (Solaris 9 seem to have the same
behaviour as Solaris 8):

% uname -a
SunOS lokrum 5.10 s10_69 i86pc i386 i86pc
% /bin/sh
$  SYSV3=1; export SYSV3
$ echo -n foobar
foobar$

Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!



 Sun, 20 May 2007 04:26:52 GMT   
 echo -n not working in /bin/sh

I always thought that the lack of -n option in /bin/sh's echo was not
a bug but a feature. To suppress the printing of the newline character
you always had to use \c escape character at the end of line. On the
other hand, /usr/ucb/echo supports -n but not the escape characters.

-akop



 Sun, 20 May 2007 05:44:20 GMT   
 echo -n not working in /bin/sh

Only on Solaris x86, not sparc:

$ man -s1 echo
...
ENVIRONMENT VARIABLES
     SYSV3    This environment variable is used to provide compa-
              tibility  with INTERACTIVE UNIX System and SCO UNIX
              installation scripts. It is intended  for  compati-
              bility only and should not be used in new scripts.

Roger Faulkner
roger.faulk...@sun.com



 Sun, 20 May 2007 12:36:25 GMT   
 echo -n not working in /bin/sh

Indeed, you are right:

$ /bin/sh
$ SYSV3=1; export SYSV3
$ echo -n foobar
-n foobar
$ uname -a
SunOS sca 5.10 s10_60 sun4u sparc SUNW,Sun-Blade-100

and

$ /bin/sh
$ SYSV3=1; export SYSV3
$ echo -n foobar
foobar$ uname -a
SunOS amanda 5.8 Generic_108529-07 i86pc

Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!



 Sun, 20 May 2007 22:15:49 GMT   
 echo -n not working in /bin/sh

This kind of inconsistency smells like a bug, doesn't it?

Maybe someone can shed light on this. Is it persistent
with newer version of solaris express?

Tom



 Sun, 20 May 2007 23:41:29 GMT   
 echo -n not working in /bin/sh

[snip]

[snip]

Nope. Read the whole message by Roger Faulkner and his quote of the man page:

$ man -s1 echo
...
ENVIRONMENT VARIABLES
     SYSV3    This environment variable is used to provide compa-
              tibility  with INTERACTIVE UNIX System and SCO UNIX
              installation scripts. It is intended  for  compati-
              bility only and should not be used in new scripts.

Since INTERACTIVE UNIX System and SCO UNIX are x86 only, this is not needed
on SPARC systems.

Bye, Dragan

--
Dragan Cvetkovic,

To be or not to be is true. G. Boole      No it isn't.  L. E. J. Brouwer

!!! Sender/From address is bogus. Use reply-to one !!!



 Sun, 20 May 2007 23:58:30 GMT   
 echo -n not working in /bin/sh

Thanks, now I understand. This is what I meant with "shed light", as I
couldn't believe that something like echo could be broken...



 Mon, 21 May 2007 00:51:03 GMT   
 echo -n not working in /bin/sh
2004-12-01, 17:51(+01), Thomas Maier-Komor:

But "echo" is probably the most broken command on Unix (in terms
of reliability, portability, consistency...)

Some implementations would turn \n into a newline character,
some wouldn't. For those which do, not all would understand \a,
\0, \0351, \351, \xE9, \c (\c could be handled differently
depending on the implementation).

Even one single implementation of echo may have a different
behavior depending on its environment (ksh for instance checks
the order of directories in PATH and maybe some other env vars
do decide between a bsd like behavior and a sysv like one).

Some echos accept a -e, -n or sometimes -E, --help, --version
(and all the variants like --he, --v...) options. Some accept
"-" as the option terminator.

With some echos, it is impossible to output the "-n" string.

So, obviously, you can't use

echo "$var"

to output an arbitrary string ($var may start with a "-" or
contain backslash characters).

That's why POSIX recommands not to use it and to use printf
instead.

--
Stephane



 Mon, 21 May 2007 18:05:01 GMT   
 echo -n not working in /bin/sh
Myself, I've now switched from echo to printf.

Does what I tell it -- and that's what counts, for me
at least.

David



 Tue, 12 Jun 2007 11:13:02 GMT   
 echo -n not working in /bin/sh
Well, having now finished reading the entire thread,
I'm *way* more convinced than before that printf
is the way to go!

That echo -- what a mess!  

David



 Tue, 12 Jun 2007 11:16:07 GMT   
 
   [ 11 post ] 

Similar Threads

1. /bin/ls and /bin/echo * same or not?

2. why /bin/sh and not /sbin/sh

3. Solaris 2.3, echo in /bin/sh

4. #!/bin/sh #!/usr/bin/sh can I do both for 2 diff machines

5. Q: What echoes faster than /bin/echo?

6. /bin/echo which does not strip leading/trailing spaces

7. write and echo do not work but wall does work

8. write and echo do not work but wall does work

9. /bin/sh not installed


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software