zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: jdh <dhenman@gmail.com>, zsh-users@zsh.org
Subject: Re: print built-in doesn't print this.
Date: Mon, 15 Nov 2021 06:30:45 +0100	[thread overview]
Message-ID: <CAHYJk3RC3RXuBN7N08ygG4+6x=8T5fXMj=kssCZrs38KHeg1iA@mail.gmail.com> (raw)
In-Reply-To: <9a8b02e1b7c697101e9be2738590cca99ac02470.camel@ntlworld.com>

On 11/14/21, Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> On Sun, 2021-11-14 at 11:19 -0800, jdh wrote:
>> I wanted to insert a string of '-'s to visually show a change in a list.
>> But  I found out that
>>
>>      print "--------"
>>
>> Does not print anything out. Well maybe a \n.
>> Is this intentional?  Or a well known feature?
>
> print has standard option syntax, so you need to terminate
> lists of options (even if they're empty) with "--".
>
> print -- "--------"
>
> The echo builtin is non-standard and doesn't have this
> requirement, but it's non-standard in a different way in
> different shells, so I'd recommend getting used to using
> print like that.

Both print and echo accept a single - to terminate the option list,
while print also accepts the double -- as seen above. echo will just
print any unknown option, while print will complain about most of them
(for some reason, -0 through -9 are just printed verbatim).

If you want to be somewhat portable across shells, the printf builtin
is usually pretty reliable. Although in many cases the format string
cannot begin with a - there either, -- seems universally accepted (I
tested bash, dash, zsh and gnu /usr/bin/printf).

PS

I use this,
alias pl='print -rl -'
which will print its arguments terminated by newlines, and the -r
means to not interpret any escapes. I think
alias pl='printf -- %s\\n'
would be more or less equivalent.

-- 
Mikael Magnusson


  reply	other threads:[~2021-11-15  5:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-14 19:19 jdh
2021-11-14 19:27 ` Norbert Zeh
2021-11-14 19:29 ` Peter Stephenson
2021-11-15  5:30   ` Mikael Magnusson [this message]
2021-11-15 16:31   ` Bart Schaefer
2021-11-15 16:46     ` Peter Stephenson
2021-11-14 19:29 ` Roman Perepelitsa
2021-11-14 19:33 ` Lawrence Velázquez
2021-11-14 21:20 ` zzapper
2021-11-15  9:50 ` zzapper

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='CAHYJk3RC3RXuBN7N08ygG4+6x=8T5fXMj=kssCZrs38KHeg1iA@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=dhenman@gmail.com \
    --cc=p.w.stephenson@ntlworld.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).