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

Re: Solaris sed

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Jun 12, 2025, 16:40 UTC
Message-ID
<CAPig+cREA6YdMgbZ59eGnU8SRWmfNR8bGGvLfTQEpS4PqKm9mg@mail.gmail.com>
In-Reply-To
<b2d23be73902c8433295e2a5f30b051d044e227c.camel@mad-scientist.net>
On Thu, Jun 12, 2025 at 9:44 AM Paul Smith <paul@mad-scientist.net> wrote:
Show 15 quoted lines
> On Thu, 2025-06-12 at 01:50 -0400, Eric Sunshine wrote:
> > Had it used the simpler:
> >
> >     echo "$foo"
> >
> > this sort of problem (forgetting the "\n") would never have occurred.
>
> Just be aware that echo is not well-standardized: many versions of echo
> accept extra options or treat certain chars specially.  So, printf
> (which IS well-standardized) is always safer unless you are 100% sure
> that the text on the echo command line is simple: cannot start with a
> "-", doesn't contain special chars like backslash, etc.
>
> For portability I (personally) always prefer printf unless I know
> exactly what the text contains (like showing a static string).

Yup, you're right. I always do the same when I can't trust the argument to be `echo`-safe, but apparently I wasn't thinking of that case when I wrote the email. Thanks for the dose of sanity.

Previous: Paul Smith
Message 15 of 15 in “Solaris sed”
  1. Brad SmithJun 12, 2025
  2. Collin FunkJun 12, 2025
  3. Brad SmithJun 12, 2025
  4. Eli SchwartzJun 12, 2025
  5. Collin FunkJun 12, 2025
  6. Brad SmithJun 12, 2025
  7. Junio C HamanoJun 12, 2025
  8. Brad SmithJun 12, 2025
  9. Collin FunkJun 12, 2025
  10. Jean-Noël AVILAJun 13, 2025
  11. Eric SunshineJun 13, 2025
  12. Collin FunkJun 13, 2025
  13. Eric SunshineJun 12, 2025
  14. Paul SmithJun 12, 2025
  15. Eric SunshineJun 12, 2025

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.