zsh-users
 help / color / mirror / code / Atom feed
From: ZyX <kp-pav@yandex.ru>
To: Peter Stephenson <p.stephenson@samsung.com>,
	"zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: The "-" and "--" options (was Re: ${var:1:1:=y})
Date: Wed, 04 Feb 2015 22:53:14 +0300	[thread overview]
Message-ID: <939361423079594@web25m.yandex.ru> (raw)
In-Reply-To: <20150204190248.3571f2e2@pwslap01u.europe.root.pri>

04.02.2015, 22:05, "Peter Stephenson" <p.stephenson@samsung.com>:
> On Wed, 4 Feb 2015 09:10:14 -0800
> Bart Schaefer <schaefer@brasslantern.com> wrote:
>>  Also "echo" does NOT accept "--" in this way, it ONLY acceps a solitary
>>  "-".  I forget why that is.
>
> I think the decision for echo (some years ago) was that it would be
> better to make it consistent with versions of /bin/echo rather than with
> the normal internal interface, since shell scripts were written to the
> external echo interface even if the shell had the builtin.
>
> It seems this argument still works on Linux at least:
>
> % /bin/echo -- foo
> -- foo
>
> so I think we were (probably) right and this is the best consistency
> we're going to get.
>
> However, there were already incompatible BSD / SYSV echoes even then, so
> it was never a full consistency with all possible external command
> variants of echo.
>
> pws

`echo` is only usable as long as the option name does not start with a dash and contains no backslashes:

====== test-echo.zsh ======
emulate -L zsh
setopt rcquotes
for shell in zsh bash tcsh fish posh dash bb mksh ksh  ; do
    eval "${shell}_echo() {
              printf 'echo %s' \"\${(j. .)\${(q)@}}\" | $shell
          }"
done
rcsh_echo() {
    printf 'echo %s' "${(j. .)${(qq)@}}" | rcsh
}
for arg in 'a\nb' 'a\\nb' '-E foo' '-e bar' '- baz' '-- bra' ; do
    typeset -A ECHO_RESULTS
    for echofunc in /bin/echo zsh_echo bash_echo tcsh_echo fish_echo posh_echo dash_echo bb_echo mksh_echo ksh_echo rcsh_echo ; do
        echo_result="S$($echofunc $=arg)E"
        ECHO_RESULTS[$echo_result]+="$echofunc "
    done
    printf '>>> %s:\n' "$arg"
    for k in ${(k)ECHO_RESULTS} ; do
        printf '%s: %s\n' "${(qqqq)k}" "${ECHO_RESULTS[$k]}"
    done
    ECHO_RESULTS=()
done
====== /test-echo.zsh ======

====== output ======
>>> a\nb:
$'Sa\nbE': zsh_echo tcsh_echo posh_echo dash_echo mksh_echo 
$'Sa\\nbE': /bin/echo bash_echo fish_echo bb_echo ksh_echo rcsh_echo 
>>> a\\nb:
$'Sa\\nbE': zsh_echo tcsh_echo posh_echo dash_echo mksh_echo 
$'Sa\\\\nbE': /bin/echo bash_echo fish_echo bb_echo ksh_echo rcsh_echo 
>>> -E foo:
$'S-E fooE': tcsh_echo posh_echo dash_echo ksh_echo rcsh_echo 
$'SfooE': /bin/echo zsh_echo bash_echo fish_echo bb_echo mksh_echo 
>>> -e bar:
$'SbarE': /bin/echo zsh_echo bash_echo fish_echo bb_echo mksh_echo ksh_echo 
$'S-e barE': tcsh_echo posh_echo dash_echo rcsh_echo 
>>> - baz:
$'S- bazE': /bin/echo bash_echo tcsh_echo posh_echo dash_echo bb_echo mksh_echo ksh_echo rcsh_echo 
$'SbazE': zsh_echo fish_echo 
>>> -- bra:
$'S-- braE': /bin/echo zsh_echo bash_echo tcsh_echo fish_echo posh_echo dash_echo bb_echo mksh_echo ksh_echo 
$'SbraE': rcsh_echo 
====== /output ======

I do not know which echo zsh behaviour is compatible, but `echo - baz` only shows `baz` in `fish`. All echo versions except rcsh one (this is by Byron Rakitzis’s Plan 9 rc shell reimplementation) (rcsh name is used in Gentoo to prevent conflict with `rc` executable from openrc initialization system) treat `--` as something they need to output, so this part is highly compatible.


  reply	other threads:[~2015-02-04 20:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-03 23:12 ${var:1:1:=y} Ray Andrews
2015-02-04  0:18 ` ${var:1:1:=y} Lawrence Velázquez
2015-02-04  0:39   ` ${var:1:1:=y} Ray Andrews
2015-02-04  1:30     ` ${var:1:1:=y} Lawrence Velázquez
2015-02-04  3:25       ` ${var:1:1:=y} Bart Schaefer
2015-02-04  3:44         ` ${var:1:1:=y} Eric Cook
2015-02-04 17:10           ` The "-" and "--" options (was Re: ${var:1:1:=y}) Bart Schaefer
2015-02-04 17:42             ` Ray Andrews
2015-02-04 23:47               ` Lawrence Velázquez
2015-02-05  1:31                 ` Ray Andrews
2015-02-05  1:52                   ` Kurtis Rader
2015-02-05  2:03                     ` Ray Andrews
2015-02-05  2:24               ` Bart Schaefer
2015-02-04 19:02             ` Peter Stephenson
2015-02-04 19:53               ` ZyX [this message]
2015-02-04  5:16         ` ${var:1:1:=y} Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=939361423079594@web25m.yandex.ru \
    --to=kp-pav@yandex.ru \
    --cc=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).