dash.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug?] echo -n does not work as described
@ 2015-11-12  1:56 Kevin Korb
  2015-11-12  3:14 ` Eric Blake
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Kevin Korb @ 2015-11-12  1:56 UTC (permalink / raw)
  To: dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit -static).

The echo builtin does not work as described.  In the man page:
 echo [-n] args...
   Print the arguments on the standard output, separated by spaces.
   Unless the -n option is present, a newline is output following the
   arguments.

However, in actual usage:
% dash
$ echo testing
testing
$ echo -n testing
- -n testing
$ /bin/echo -n testing
testing$

This is causing me problems when I attempt to switch /bin/sh from bash
to dash.

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
- -*~
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
- -*~
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZD8bIACgkQVKC1jlbQAQc0DQCaAt6x4XveLhPjaPiPaSG8ll5a
3ZEAn0J5mkr1wd7Nd2l3Q6xKpB2LZ39+
=lljb
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  1:56 [bug?] echo -n does not work as described Kevin Korb
@ 2015-11-12  3:14 ` Eric Blake
  2015-11-12  3:40   ` Kevin Korb
  2015-11-12  8:10 ` Bastian Bittorf
  2015-11-12 10:03 ` Petr Šabata
  2 siblings, 1 reply; 13+ messages in thread
From: Eric Blake @ 2015-11-12  3:14 UTC (permalink / raw)
  To: Kevin Korb, dash

[-- Attachment #1: Type: text/plain, Size: 1383 bytes --]

On 11/11/2015 06:56 PM, Kevin Korb wrote:
> I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit -static).
> 
> The echo builtin does not work as described.  In the man page:

Which man page? Coreutils'?

Read it further:

>  NOTE: your shell may have its own version of echo, which usually super‐
> sedes the version described here. Please refer to your shell's docu‐
> mentation for details about the options it supports.

By the way, 'echo -n' is non-portable, and POSIX says you should use
'printf' instead.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html

    A string to be written to standard output. If the first operand is
-n, or if any of the operands contain a <backslash> character, the
results are implementation-defined.

> $ echo -n testing
> -n testing

Dash's implementation-defined behavior for -n is to treat it the same as
every other string.  Thus, this is not a bug in dash, at least according
to POSIX.

> This is causing me problems when I attempt to switch /bin/sh from bash
> to dash.

It's probably not the only bashism you've been relying on.  You may want
to try using checkbashisms
(http://sourceforge.net/projects/checkbaskisms/) to help you find other
portability pitfalls.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  3:14 ` Eric Blake
@ 2015-11-12  3:40   ` Kevin Korb
  2015-11-12  3:46     ` Kevin Korb
  0 siblings, 1 reply; 13+ messages in thread
From: Kevin Korb @ 2015-11-12  3:40 UTC (permalink / raw)
  To: Eric Blake, dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/11/2015 10:14 PM, Eric Blake wrote:
> On 11/11/2015 06:56 PM, Kevin Korb wrote:
>> I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit
>> -static).
>> 
>> The echo builtin does not work as described.  In the man page:
> 
> Which man page? Coreutils'?

I was quoting the dash man page.  I did quote the result of the
coreutils version of echo (/bin/echo) which worked correctly.

> Read it further:
> 
>> NOTE: your shell may have its own version of echo, which usually
>> super‐ sedes the version described here. Please refer to your
>> shell's docu‐ mentation for details about the options it
>> supports.
> 
> By the way, 'echo -n' is non-portable, and POSIX says you should
> use 'printf' instead.

This isn't my problem.  I am trying to use dash as a replacement for
/bin/sh and it is failing horribly.  I am not the authors of the
problem scripts.  Plus, frankly, it is absurd to require printf where
echo [-n] should work correctly according to the dash documentation.

> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
>
>  A string to be written to standard output. If the first operand
> is -n, or if any of the operands contain a <backslash> character,
> the results are implementation-defined.
> 
>> $ echo -n testing -n testing
> 
> Dash's implementation-defined behavior for -n is to treat it the
> same as every other string.  Thus, this is not a bug in dash, at
> least according to POSIX.

Either this is a bug in dash or in dash's man page.  The man page is
clear about how echo and echo -n should work.  But the reality is very
different.

>> This is causing me problems when I attempt to switch /bin/sh from
>> bash to dash.

This isn't stuff I have written.  This is stuff that I am tired of
modifying to be dash compatible.

Either dash's echo command should operate as documented or the
documentation should be corrected.

> It's probably not the only bashism you've been relying on.  You may
> want to try using checkbashisms 
> (http://sourceforge.net/projects/checkbaskisms/) to help you find
> other portability pitfalls.
> 

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZECh4ACgkQVKC1jlbQAQfK3ACeN1EC20BVyzwnSXTndBCchYS0
tHkAoKANsc2eL1imSW6u8oSpJ9VaerOc
=20HJ
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  3:40   ` Kevin Korb
@ 2015-11-12  3:46     ` Kevin Korb
  2015-11-12  8:35       ` Seb
  2015-11-12 21:24       ` Stephane Chazelas
  0 siblings, 2 replies; 13+ messages in thread
From: Kevin Korb @ 2015-11-12  3:46 UTC (permalink / raw)
  To: Eric Blake, dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 11/11/2015 10:40 PM, Kevin Korb wrote:
> On 11/11/2015 10:14 PM, Eric Blake wrote:
>> On 11/11/2015 06:56 PM, Kevin Korb wrote:
>>> I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit 
>>> -static).
>>> 
>>> The echo builtin does not work as described.  In the man page:
> 
>> Which man page? Coreutils'?

no, /usr/share/man/man1/dash.1.xz on my box

> I was quoting the dash man page.  I did quote the result of the 
> coreutils version of echo (/bin/echo) which worked correctly.
> 
>> Read it further:
> 
>>> NOTE: your shell may have its own version of echo, which
>>> usually super‐ sedes the version described here. Please refer
>>> to your shell's docu‐ mentation for details about the options
>>> it supports.
> 
>> By the way, 'echo -n' is non-portable, and POSIX says you should 
>> use 'printf' instead.

If dash refuses to supply a compatible version of echo then dash must
not include a builtin version of echo.  If dash didn't have a broken
embedded version of echo I wouldn't have a problem.

> This isn't my problem.  I am trying to use dash as a replacement
> for /bin/sh and it is failing horribly.  I am not the authors of
> the problem scripts.  Plus, frankly, it is absurd to require printf
> where echo [-n] should work correctly according to the dash
> documentation.
> 
>> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html
>
>>  A string to be written to standard output. If the first operand 
>> is -n, or if any of the operands contain a <backslash>
>> character, the results are implementation-defined.
> 
>>> $ echo -n testing -n testing
> 
>> Dash's implementation-defined behavior for -n is to treat it the 
>> same as every other string.  Thus, this is not a bug in dash, at 
>> least according to POSIX.

Then why does the man page say otherwise?

> Either this is a bug in dash or in dash's man page.  The man page
> is clear about how echo and echo -n should work.  But the reality
> is very different.
> 
>>> This is causing me problems when I attempt to switch /bin/sh
>>> from bash to dash.
> 
> This isn't stuff I have written.  This is stuff that I am tired of 
> modifying to be dash compatible.
> 
> Either dash's echo command should operate as documented or the 
> documentation should be corrected.
> 
>> It's probably not the only bashism you've been relying on.  You
>> may want to try using checkbashisms 
>> (http://sourceforge.net/projects/checkbaskisms/) to help you
>> find other portability pitfalls.

> -- To unsubscribe from this list: send the line "unsubscribe dash"
> in the body of a message to majordomo@vger.kernel.org More
> majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZEC3oACgkQVKC1jlbQAQfJawCeIdQetXk4zloxdAWk0+ZmreeQ
bX4AniCxpW0lwUSzkcO80nAru1xU5RQr
=belp
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  1:56 [bug?] echo -n does not work as described Kevin Korb
  2015-11-12  3:14 ` Eric Blake
@ 2015-11-12  8:10 ` Bastian Bittorf
  2015-11-12 16:11   ` Kevin Korb
  2015-11-12 10:03 ` Petr Šabata
  2 siblings, 1 reply; 13+ messages in thread
From: Bastian Bittorf @ 2015-11-12  8:10 UTC (permalink / raw)
  To: Kevin Korb; +Cc: dash

* Kevin Korb <kmk@sanitarium.net> [12.11.2015 08:52]:
> $ echo -n testing
> - -n testing

in POSIX the '-n' switch (and -e) is undefined.
you can work around this via hijacking the call:

#!/bin/sh
echo()
{
	case "$1" in
		'-n')
			shift
			printf '%s' "$@"
		;;
		*)
			printf '%s\n' "$@"
		;;
	esac
}

echo foo
echo -n bar

if you really want to remove all the bashisms, it
can be a lot of work. dont blame dash for this, but
the script author. also consider using shellsheck.net
for this with the correct shebang.

bye, bastian

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  3:46     ` Kevin Korb
@ 2015-11-12  8:35       ` Seb
  2015-11-12 16:12         ` Kevin Korb
  2015-11-12 21:24       ` Stephane Chazelas
  1 sibling, 1 reply; 13+ messages in thread
From: Seb @ 2015-11-12  8:35 UTC (permalink / raw)
  To: dash; +Cc: Kevin Korb

On Wed, Nov 11, 2015 at 10:46:02PM -0500, Kevin Korb wrote:

> >> By the way, 'echo -n' is non-portable, and POSIX says you
> >> should use 'printf' instead.
> 
> If dash refuses to supply a compatible version of echo then
> dash must not include a builtin version of echo.  If dash
> didn't have a broken embedded version of echo I wouldn't have a
> problem.

dash just claims to be compatible with POSIX, not with *sh. If
you look for something like this (lighter than bash but with many
of its features), glance rather at mksh:

  https://www.mirbsd.org/mksh.htm

Now, I don't understand the present issue, all seems just work as
expected here (0.5.8):

 $ dash -c 'type echo; echo -n foo; echo foo'
 echo is a shell builtin
 foofoo

++
Seb.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  1:56 [bug?] echo -n does not work as described Kevin Korb
  2015-11-12  3:14 ` Eric Blake
  2015-11-12  8:10 ` Bastian Bittorf
@ 2015-11-12 10:03 ` Petr Šabata
  2015-11-12 16:18   ` Kevin Korb
  2 siblings, 1 reply; 13+ messages in thread
From: Petr Šabata @ 2015-11-12 10:03 UTC (permalink / raw)
  To: Kevin Korb; +Cc: dash

[-- Attachment #1: Type: text/plain, Size: 1132 bytes --]

On Wed, Nov 11, 2015 at 08:56:02PM -0500, Kevin Korb wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit -static).
> 
> The echo builtin does not work as described.  In the man page:
>  echo [-n] args...
>    Print the arguments on the standard output, separated by spaces.
>    Unless the -n option is present, a newline is output following the
>    arguments.
> 
> However, in actual usage:
> % dash
> $ echo testing
> testing
> $ echo -n testing
> - -n testing
> $ /bin/echo -n testing
> testing$
> 
> This is causing me problems when I attempt to switch /bin/sh from bash
> to dash.

Hmm, where does the 0.5.8.2 version come from, I wonder?
The latest release is 0.5.8 [0] and I cannot reproduce your
issue with it on Fedora [1] (and note that, afaik, Fedora doesn't
apply any special patches that could affect this behavior).

Try rebuilding dash with USE=-libedit and see if it changes
anything.  If not -- I would bug the Gentoo maintainers.

P

[0] http://gondor.apana.org.au/~herbert/dash/
[1] dash-0.5.8-3.fc23.x86_64

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  8:10 ` Bastian Bittorf
@ 2015-11-12 16:11   ` Kevin Korb
  2015-11-19 12:36     ` Bastian Bittorf
  0 siblings, 1 reply; 13+ messages in thread
From: Kevin Korb @ 2015-11-12 16:11 UTC (permalink / raw)
  To: Bastian Bittorf; +Cc: dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Then why is the -n behaviour documented in the man page?

On 11/12/2015 03:10 AM, Bastian Bittorf wrote:
> * Kevin Korb <kmk@sanitarium.net> [12.11.2015 08:52]:
>> $ echo -n testing - -n testing
> 
> in POSIX the '-n' switch (and -e) is undefined. you can work around
> this via hijacking the call:
> 
> #!/bin/sh echo() { case "$1" in '-n') shift printf '%s' "$@" ;; *) 
> printf '%s\n' "$@" ;; esac }
> 
> echo foo echo -n bar
> 
> if you really want to remove all the bashisms, it can be a lot of
> work. dont blame dash for this, but the script author. also
> consider using shellsheck.net for this with the correct shebang.
> 
> bye, bastian -- To unsubscribe from this list: send the line
> "unsubscribe dash" in the body of a message to
> majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html
> 

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZEujcACgkQVKC1jlbQAQfIuQCeJrtFu94ThY+48k5zphx+s1i/
mJAAn2zHqfppmvh7mCrWuXHJGnkq9XJ6
=pqKh
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  8:35       ` Seb
@ 2015-11-12 16:12         ` Kevin Korb
  0 siblings, 0 replies; 13+ messages in thread
From: Kevin Korb @ 2015-11-12 16:12 UTC (permalink / raw)
  To: Seb, dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This is what I get:
% dash -c 'type echo; echo -n foo; echo foo'
echo is a shell builtin
- -n foo
foo


On 11/12/2015 03:35 AM, Seb wrote:
> On Wed, Nov 11, 2015 at 10:46:02PM -0500, Kevin Korb wrote:
> 
>>>> By the way, 'echo -n' is non-portable, and POSIX says you 
>>>> should use 'printf' instead.
>> 
>> If dash refuses to supply a compatible version of echo then dash
>> must not include a builtin version of echo.  If dash didn't have
>> a broken embedded version of echo I wouldn't have a problem.
> 
> dash just claims to be compatible with POSIX, not with *sh. If you
> look for something like this (lighter than bash but with many of
> its features), glance rather at mksh:
> 
> https://www.mirbsd.org/mksh.htm
> 
> Now, I don't understand the present issue, all seems just work as 
> expected here (0.5.8):
> 
> $ dash -c 'type echo; echo -n foo; echo foo' echo is a shell
> builtin foofoo
> 
> ++ Seb.
> 
> -- To unsubscribe from this list: send the line "unsubscribe dash"
> in the body of a message to majordomo@vger.kernel.org More
> majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZEumwACgkQVKC1jlbQAQciqwCeNRjcqFps3ZNtisqM3UI2rlQn
3NMAn2DAvJuycgyFnDTf10jP3y4Gu8x9
=lCLu
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12 10:03 ` Petr Šabata
@ 2015-11-12 16:18   ` Kevin Korb
  2015-11-12 16:55     ` Kevin Korb
  0 siblings, 1 reply; 13+ messages in thread
From: Kevin Korb @ 2015-11-12 16:18 UTC (permalink / raw)
  To: dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

AHA!  Now we are getting somewhere.  I compiled dash myself and it
behaved properly.  I then tracked my problem to this Gentoo patch:
https://gitweb.gentoo.org/repo/gentoo.git/tree/app-shells/dash/files/das
h-0.5.8.1-dumb-echo.patch

So, apparently my problem is with Gentoo not dash.  Thanks for helping
me figure that out.

On 11/12/2015 05:03 AM, Petr Šabata wrote:
> On Wed, Nov 11, 2015 at 08:56:02PM -0500, Kevin Korb wrote:
>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>> 
>> I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit
>> -static).
>> 
>> The echo builtin does not work as described.  In the man page: 
>> echo [-n] args... Print the arguments on the standard output,
>> separated by spaces. Unless the -n option is present, a newline
>> is output following the arguments.
>> 
>> However, in actual usage: % dash $ echo testing testing $ echo -n
>> testing - -n testing $ /bin/echo -n testing testing$
>> 
>> This is causing me problems when I attempt to switch /bin/sh from
>> bash to dash.
> 
> Hmm, where does the 0.5.8.2 version come from, I wonder? The latest
> release is 0.5.8 [0] and I cannot reproduce your issue with it on
> Fedora [1] (and note that, afaik, Fedora doesn't apply any special
> patches that could affect this behavior).
> 
> Try rebuilding dash with USE=-libedit and see if it changes 
> anything.  If not -- I would bug the Gentoo maintainers.
> 
> P
> 
> [0] http://gondor.apana.org.au/~herbert/dash/ [1]
> dash-0.5.8-3.fc23.x86_64
> 

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZEu9wACgkQVKC1jlbQAQes8gCaA39BdrLiTABBFuiehKwIus0/
jDEAoNQuoxqXSR8FSxJxPS6UrG7qZIUB
=mtMj
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12 16:18   ` Kevin Korb
@ 2015-11-12 16:55     ` Kevin Korb
  0 siblings, 0 replies; 13+ messages in thread
From: Kevin Korb @ 2015-11-12 16:55 UTC (permalink / raw)
  To: dash

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

For future reference, I did some reading in Gentoo's bugzilla...

Apparently the Gentoo devs broke dash's echo -n on purpose.  Their
intention is to cause any shell script that is called with /bin/sh to
fail if the script uses echo -n.  However, they didn't limit this
behaviour to dash as /bin/sh as it happens as /bin/dash too and they
didn't modify the man page and they didn't break bash this way.

So, I am calling this a stupid Gentooism and I am forking their ebuild
for my own systems with that patch commented out.

On 11/12/2015 11:18 AM, Kevin Korb wrote:
> AHA!  Now we are getting somewhere.  I compiled dash myself and it 
> behaved properly.  I then tracked my problem to this Gentoo patch: 
> https://gitweb.gentoo.org/repo/gentoo.git/tree/app-shells/dash/files/d
as
>
> 
h-0.5.8.1-dumb-echo.patch
> 
> So, apparently my problem is with Gentoo not dash.  Thanks for
> helping me figure that out.
> 
> On 11/12/2015 05:03 AM, Petr Šabata wrote:
>> On Wed, Nov 11, 2015 at 08:56:02PM -0500, Kevin Korb wrote:
>>> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
>>> 
>>> I am on dash version 0.5.8.2 on Gentoo Linux (USE=libedit 
>>> -static).
>>> 
>>> The echo builtin does not work as described.  In the man page:
>>>  echo [-n] args... Print the arguments on the standard output, 
>>> separated by spaces. Unless the -n option is present, a
>>> newline is output following the arguments.
>>> 
>>> However, in actual usage: % dash $ echo testing testing $ echo
>>> -n testing - -n testing $ /bin/echo -n testing testing$
>>> 
>>> This is causing me problems when I attempt to switch /bin/sh
>>> from bash to dash.
> 
>> Hmm, where does the 0.5.8.2 version come from, I wonder? The
>> latest release is 0.5.8 [0] and I cannot reproduce your issue
>> with it on Fedora [1] (and note that, afaik, Fedora doesn't apply
>> any special patches that could affect this behavior).
> 
>> Try rebuilding dash with USE=-libedit and see if it changes 
>> anything.  If not -- I would bug the Gentoo maintainers.
> 
>> P
> 
>> [0] http://gondor.apana.org.au/~herbert/dash/ [1] 
>> dash-0.5.8-3.fc23.x86_64
> 
> 
> -- To unsubscribe from this list: send the line "unsubscribe dash"
> in the body of a message to majordomo@vger.kernel.org More
> majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

- -- 
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin@FutureQuest.net  (work)
	Orlando, Florida		kmk@sanitarium.net (personal)
	Web page:			http://www.sanitarium.net/
	PGP public key available on web site.
~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,-*~'`^`'~*-,._.,
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlZExH8ACgkQVKC1jlbQAQcWQACg92JXp/RNRl5Bw3qGeFzQF8hq
aXIAoK13wl6ELE9BEfFjRd1qJoWk26lC
=xFAp
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12  3:46     ` Kevin Korb
  2015-11-12  8:35       ` Seb
@ 2015-11-12 21:24       ` Stephane Chazelas
  1 sibling, 0 replies; 13+ messages in thread
From: Stephane Chazelas @ 2015-11-12 21:24 UTC (permalink / raw)
  To: Kevin Korb; +Cc: Eric Blake, dash

2015-11-11 22:46:02 -0500, Kevin Korb:
[...]
> >>> NOTE: your shell may have its own version of echo, which
> >>> usually super‐ sedes the version described here. Please refer
> >>> to your shell's docu‐ mentation for details about the options
> >>> it supports.
> > 
> >> By the way, 'echo -n' is non-portable, and POSIX says you should 
> >> use 'printf' instead.
> 
> If dash refuses to supply a compatible version of echo then dash must
> not include a builtin version of echo.  If dash didn't have a broken
> embedded version of echo I wouldn't have a problem.
[...]

To clarify, a few things, sh and the POSIX/Unix utilities like C
nowadays is a language that has a (well several) standard that
defines it, and several existing implementations of interpreters
that interpret that language.

Among the most recognised specifications, we have POSIX and
Unix. Both specifications have now been merged. To simplify, the
Unix spec is like the POSIX spec but where a few optional parts
are required.

So basically we have the POSIX syntax for sh and utilities and
the Unix syntax.

In the POSIX syntax, the behaviour for:

echo -n whatever

is unspecified. That means that a POSIX conformant script, or a
script written to be portable to POSIX conformant systems must
not call echo with a first argument that may be -n. We're told
to use printf instead there:

printf %s "$var"
instead of
echo -n "$var"

Same goes for any argument that contains backslash character.

In the Unix syntax however, the behaviour of echo is clearly
specified.

echo -n whatever

is required to output "-n whatever<newline>", so your dash is
both POSIX and Unix conformant in that regard.

The builtin echo of bash, by default is neither POSIX nor Unix
conformant unless both the xpg_echo and posix (that one enabled
when called as sh) options have been enabled.

More details at:

http://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo

In short, don't use echo.

-- 
Stephane

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [bug?] echo -n does not work as described
  2015-11-12 16:11   ` Kevin Korb
@ 2015-11-19 12:36     ` Bastian Bittorf
  0 siblings, 0 replies; 13+ messages in thread
From: Bastian Bittorf @ 2015-11-19 12:36 UTC (permalink / raw)
  To: Kevin Korb; +Cc: dash

* Kevin Korb <kmk@sanitarium.net> [19.11.2015 13:21]:
> Then why is the -n behaviour documented in the man page?

Because '-n' works with 'dash'.
Undefined means: it depends on the implementation.

bye, bastian

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-11-19 12:37 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-12  1:56 [bug?] echo -n does not work as described Kevin Korb
2015-11-12  3:14 ` Eric Blake
2015-11-12  3:40   ` Kevin Korb
2015-11-12  3:46     ` Kevin Korb
2015-11-12  8:35       ` Seb
2015-11-12 16:12         ` Kevin Korb
2015-11-12 21:24       ` Stephane Chazelas
2015-11-12  8:10 ` Bastian Bittorf
2015-11-12 16:11   ` Kevin Korb
2015-11-19 12:36     ` Bastian Bittorf
2015-11-12 10:03 ` Petr Šabata
2015-11-12 16:18   ` Kevin Korb
2015-11-12 16:55     ` Kevin Korb

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).