From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26007 invoked by alias); 4 Feb 2015 20:00:56 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19815 Received: (qmail 9943 invoked from network); 4 Feb 2015 20:00:52 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_FSL_HELO_BARE_IP_2 autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1423079595; bh=v87lCCDqzpt5ENpm+XI1m+/qGzcSM8OVsglQUedHxa0=; h=From:To:In-Reply-To:References:Subject:Date; b=FMdpkVCZ14xM0PyPolFx2BCL9qeqLi6Gj7iOftOwGeJqbn4Hl3mRlMBOBl5QnRumj 94C3o+fuTaYx3oISUeGR3O7AGBPEz1T14Scd/2Opn8gJ4RtMtIfpMVEzWGeynN8Vjy WwwZgyaTNn1iAJ+KP2XIgY/E9HEdyoPcvfcRSejM= From: ZyX To: Peter Stephenson , "zsh-users@zsh.org" In-Reply-To: <20150204190248.3571f2e2@pwslap01u.europe.root.pri> References: <54D155C8.4080600@eastlink.ca> <412544FB-49A2-43AA-BC76-DC1AF1AA71BE@larryv.me> <54D16A4C.9010609@eastlink.ca> <150203192508.ZM2159@torch.brasslantern.com> <54D195B2.4070205@gmx.com> <150204091014.ZM3216@torch.brasslantern.com> <20150204190248.3571f2e2@pwslap01u.europe.root.pri> Subject: Re: The "-" and "--" options (was Re: ${var:1:1:=y}) MIME-Version: 1.0 Message-Id: <939361423079594@web25m.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Wed, 04 Feb 2015 22:53:14 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 04.02.2015, 22:05, "Peter Stephenson" : > On Wed, 4 Feb 2015 09:10:14 -0800 > Bart Schaefer 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.