Re: Solaris sed
- From
Paul Smith <paul@mad-scientist.net>
- Date
- Jun 12, 2025, 13:35 UTC
- Message-ID
- <b2d23be73902c8433295e2a5f30b051d044e227c.camel@mad-scientist.net>
- In-Reply-To
- <CAPig+cROcMt1crKjvqcetFNGdE4ywmD1+NO+q+MnDzctx8ewag@mail.gmail.com>
On Thu, 2025-06-12 at 01:50 -0400, Eric Sunshine wrote:
Show 5 quoted lines
> 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).