From: Stephane CHAZELAS on
2010-03-21, 18:44(+01), Sidney Lambe:
> On comp.unix.shell, Christian Brabandt <cb-news(a)256bit.org> wrote:
[...]
>> chrisbra(a)256bit:~$ echo -e "foobar\none\ntwo" |sed -e '/foobar/a\
>> > baz
>> > '
>> foobar
>> baz
>> one
>> two
[...]
> sed -i '/regex/a line one\
> line two ' file
[...]


Would have been OK in comp.gnu.shell. It's OK in
comp.unix.shell, as long as you also mention that "-i" and
having something following the "a" command are non-standard
extensions recognised only by a some versions of a few sed
implementations.

Christian's sed command is the standard way to write it. However,
his echo command is non standard (but would have been OK in
comp.gnu.shell)

--
Stéphane
From: Stephane CHAZELAS on
2010-03-22, 02:43(+01), Sidney Lambe:
[...]
>>>> chrisbra(a)256bit:~$ echo -e "foobar\none\ntwo" |sed -e '/foobar/a\
[...]
>>> sed -i '/regex/a line one\
[...]
> Okay. Thanks. How about if I include: GNU sed version 4.1.5?

Yes, though there do exist a few other implementations that
support it as well. I believe GNU sed was the one that
introduced "-i" (inspired from perl's -i).

> How about /bin/echo for Christian's script?

Only on systems where /bin/echo is not POSIX, like some GNU
or BSD systems. There's no guarantee that there be an "echo"
command in /bin, though that would be very unusual.

> Or /bin/printf?
[...]

printf 'foobar\none\ntwo\n'

is POSIX and Unix, and is the POSIX recommended alternative to
the non-portable echo command.

echo 'foobar\none\ntwo'

would work on Unix systems.

--
Stéphane
From: Allodoxaphobia on
On Mon, 22 Mar 2010 16:30:41 +0000 (UTC), Stephane CHAZELAS wrote:
>
> echo 'foobar\none\ntwo'
>
> would work on Unix systems.

And, it's

echo -e 'foobar\none\ntwo'

on linux and FreeBSD.


" Standards are *GREAT!* "
" And there are *SO MANY* to chose from. "

From: Chris F.A. Johnson on
On 2010-03-22, Allodoxaphobia wrote:
> On Mon, 22 Mar 2010 16:30:41 +0000 (UTC), Stephane CHAZELAS wrote:
>>
>> echo 'foobar\none\ntwo'
>>
>> would work on Unix systems.
>
> And, it's
>
> echo -e 'foobar\none\ntwo'
>
> on linux and FreeBSD.

Not necessarily. On Linux and FreeBSD one can be running shells
other than bash; it wouldn't work in those.

To be portable, use printf.

--
Chris F.A. Johnson, author <http://shell.cfajohnson.com/>
===================================================================
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
===== My code in this post, if any, assumes the POSIX locale =====
===== and is released under the GNU General Public Licence =====
From: Stephane CHAZELAS on
2010-03-23, 17:49(+00), Chris F.A. Johnson:
> On 2010-03-22, Allodoxaphobia wrote:
>> On Mon, 22 Mar 2010 16:30:41 +0000 (UTC), Stephane CHAZELAS wrote:
>>>
>>> echo 'foobar\none\ntwo'
>>>
>>> would work on Unix systems.
>>
>> And, it's
>>
>> echo -e 'foobar\none\ntwo'
>>
>> on linux and FreeBSD.
>
> Not necessarily. On Linux and FreeBSD one can be running shells
> other than bash; it wouldn't work in those.
[...]

Well, that's not only about bash. Bash wasn't the one that
introduced -e (AFAICT). See Sven's
http://www.in-ulm.de/~mascheck/various/echo+printf/ for details:

> To be portable, use printf.

Definitely.


--
Stéphane