[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: which echo understand \n



On Thu, Jun 01, 2000 at 05:03:09PM -0300, suntong001@yahoo.com wrote:
> hi,                  
> 
> The /bin/echo I used to use in Solaris understand \n and \t stuffs    
> by default. Is there any trick I can play so that I don't need to 
> specify the -e parameter for echo? 

use printf instead.  printing \t \n type things with echo is completly
non-portable any more.  some echos use echo foo\c for a newline some
need -e some don't.  

> The reason I'm asking is that debian is the only un*x I've used that 
> /bin/echo don't interprate \n... by default. I've already wirtten 
> tons of scripts using /bin/echo. Please help. 

hmm Digital UNIX (aka OSF/4) needs -e, OpenBSD /bin/echo needs -e, GNU
echo needs -e, bash builtin echo needs -e ...  (OpenBSD's /bin/sh has
a builtin echo which does not need -e but /bin/echo does)

you really can't depend on any echo doing anything consistently
unfortunatly.  printf on the other hand behaves perfectly consistent
on GNU/Linux, OpenBSD, SunOS 5.7, Digital UNIX (OSF/4) and i presume
just about everything else (those are all i have access to)

if you don't want to use printf (or can't) you could replace your echo
commands with $echo and do a test like so:

if [ `echo "foo\n"` = "foo\n" ] ; then
	echo="echo -e"
else
	echo="echo" 
fi

which may or may not be reliable...

my advice is use printf unless your script must work on stripped down
systems like rescue floppies or / without /usr mounted.  (or anything
else abnormal)

-- 
Ethan Benson
http://www.alaska.net/~erbenson/

Attachment: pgpJKHpwyao_x.pgp
Description: PGP signature


Reply to: