git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Use printf rather than echo -n.

From
Junio C Hamano <junkio@cox.net>
Date
Dec 7, 2005, 02:04 UTC
Message-ID
<7vfyp5zmqe.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20512.1133907712@lotus.CS.Berkeley.EDU>
Jason Riedy <ejr@EECS.Berkeley.EDU> writes:
Show 7 quoted lines
> On AIX, there is no -n option to the system's echo.  Instead,
> it needs the '\c' control character.  We could replace
>   echo -n "foo"
> with
>   echo -e "foo\c"
> but printf is recommended by most man pages.  Tested on AIX
> 5.3, Solaris 8, and Debian.
Hmmmmmmmmmmmmmmmmmmmmmmmm.

Perhaps printf '%s' "$blah" to futureproof, instead of just saying printf "$blah"?

<rant mode on> While I do not have anything aginst system without "sane" echo, I really do not like it. Not your solution, but *having to do* something like that.

metaconfig Configure does "echo $n frotz $c" with n=-n or c=\\c set appropriately; autoconf does the same with $ac_n $ac_c. IIRC, I think ancient autoconf did "echo | tr -d '\012'".

These are far worse than a single printf, although they may be more portable.

</rant mode off>

As a traditionalist, if I were doing it myself I would probably pipe echo to tr, but I am lazy so I'd take your patch as is ;-).

Previous: Jason RiedyNext: Jason Riedy
Message 2 of 3 in “Use printf rather than echo -n.”
  1. Use printf rather than echo -n.Jason Riedy, Dec 6, 2005
  2. Junio C HamanoDec 7, 2005
  3. Jason RiedyDec 7, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.