zsh-users
 help / color / mirror / code / Atom feed
* print built-in doesn't print this.
@ 2021-11-14 19:19 jdh
  2021-11-14 19:27 ` Norbert Zeh
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: jdh @ 2021-11-14 19:19 UTC (permalink / raw)
  To: zsh-users


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?

DH


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

* Re: print built-in doesn't print this.
  2021-11-14 19:19 print built-in doesn't print this jdh
@ 2021-11-14 19:27 ` Norbert Zeh
  2021-11-14 19:29 ` Peter Stephenson
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Norbert Zeh @ 2021-11-14 19:27 UTC (permalink / raw)
  To: zsh-users

Print seems to parse the ‘-----------------‘ as command line options, which you can test using “print ‘------------------0’”.  If you type “print -- ‘-----------------‘“, you get the result you want.

Cheers,

Norbert Zeh
norbert.zeh@gmail.com



> On Nov 14, 2021, at 3:19 PM, jdh <dhenman@gmail.com> wrote:
> 
> CAUTION: The Sender of this email is not from within Dalhousie.
> 
> 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?
> 
> DH
> 



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

* Re: print built-in doesn't print this.
  2021-11-14 19:19 print built-in doesn't print this jdh
  2021-11-14 19:27 ` Norbert Zeh
@ 2021-11-14 19:29 ` Peter Stephenson
  2021-11-15  5:30   ` Mikael Magnusson
  2021-11-15 16:31   ` Bart Schaefer
  2021-11-14 19:29 ` Roman Perepelitsa
                   ` (3 subsequent siblings)
  5 siblings, 2 replies; 10+ messages in thread
From: Peter Stephenson @ 2021-11-14 19:29 UTC (permalink / raw)
  To: jdh, zsh-users

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.

pws





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

* Re: print built-in doesn't print this.
  2021-11-14 19:19 print built-in doesn't print this jdh
  2021-11-14 19:27 ` Norbert Zeh
  2021-11-14 19:29 ` Peter Stephenson
@ 2021-11-14 19:29 ` Roman Perepelitsa
  2021-11-14 19:33 ` Lawrence Velázquez
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Roman Perepelitsa @ 2021-11-14 19:29 UTC (permalink / raw)
  To: jdh; +Cc: Zsh Users

On Sun, Nov 14, 2021 at 8:21 PM jdh <dhenman@gmail.com> wrote:
>
> I wanted to insert a string of '-'s to visually show a change in a list.
> But  I found out that
>
>      print "--------"

This should do it:

    print -- "--------"

It's unfortunate that print doesn't report an error with the original
arguments. UNIX utilities usually do:

BSD:

    % ls --------
    ls: unrecognized option `--------'
    usage: ls [snip]

GNU:

    % ls --------
    ls: unrecognized option `--------'
    Try 'ls --help' for more information.

Roman.


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

* Re: print built-in doesn't print this.
  2021-11-14 19:19 print built-in doesn't print this jdh
                   ` (2 preceding siblings ...)
  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
  5 siblings, 0 replies; 10+ messages in thread
From: Lawrence Velázquez @ 2021-11-14 19:33 UTC (permalink / raw)
  To: jdh; +Cc: zsh-users

On Sun, Nov 14, 2021, at 2:19 PM, 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?

It's interpreting "--------" as an option.  To print strings that
begin with "-" you can use the common "--" idiom to indicate that
subsequent arguments should not be interpreted as options.

    % print ------

    % print -- ------
    ------

-- 
vq


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

* Re: print built-in doesn't print this.
  2021-11-14 19:19 print built-in doesn't print this jdh
                   ` (3 preceding siblings ...)
  2021-11-14 19:33 ` Lawrence Velázquez
@ 2021-11-14 21:20 ` zzapper
  2021-11-15  9:50 ` zzapper
  5 siblings, 0 replies; 10+ messages in thread
From: zzapper @ 2021-11-14 21:20 UTC (permalink / raw)
  To: zsh-users


On 14/11/2021 19:19, 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.
>
> ls --------
ls: unrecognised option '--------'
Try 'ls --help' for more information.
  > ls -- --------
ls: cannot access '--------': No such file or directory

-- is useful for avoiding ambiguity

And is also used with zargs  ##  but is that he same thing?

zargs  /tmp/*(.m+30) -- rm

zzapper



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

* Re: print built-in doesn't print this.
  2021-11-14 19:29 ` Peter Stephenson
@ 2021-11-15  5:30   ` Mikael Magnusson
  2021-11-15 16:31   ` Bart Schaefer
  1 sibling, 0 replies; 10+ messages in thread
From: Mikael Magnusson @ 2021-11-15  5:30 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: jdh, zsh-users

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


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

* Re: print built-in doesn't print this.
  2021-11-14 19:19 print built-in doesn't print this jdh
                   ` (4 preceding siblings ...)
  2021-11-14 21:20 ` zzapper
@ 2021-11-15  9:50 ` zzapper
  5 siblings, 0 replies; 10+ messages in thread
From: zzapper @ 2021-11-15  9:50 UTC (permalink / raw)
  To: Zsh-Users List


On 14/11/2021 19:19, jdh wrote:
> I wanted to insert a string of '-'s to visually show a change in a list.
> But  I found out that
>
>       print "--------"
>
# recap

 > echo  ------
------
 > echo - ----

----

 > echo -- ----

-- ----

print ------

<nothing>

 > print - ----
----

 > print -- ----
----




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

* Re: print built-in doesn't print this.
  2021-11-14 19:29 ` Peter Stephenson
  2021-11-15  5:30   ` Mikael Magnusson
@ 2021-11-15 16:31   ` Bart Schaefer
  2021-11-15 16:46     ` Peter Stephenson
  1 sibling, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2021-11-15 16:31 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: jdh, Zsh Users

On Sun, Nov 14, 2021 at 11:33 AM Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
>
> print has standard option syntax, so you need to terminate
> lists of options (even if they're empty) with "--".

True statement but I think something else is going on here.

% set "--------" a b c
% print $argv
a b c

Zsh's generic option parser is consuming any number of consecutive
hyphens as "--".  That's probably not right.


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

* Re: print built-in doesn't print this.
  2021-11-15 16:31   ` Bart Schaefer
@ 2021-11-15 16:46     ` Peter Stephenson
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Stephenson @ 2021-11-15 16:46 UTC (permalink / raw)
  To: Zsh Users

> On 15 November 2021 at 16:31 Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Sun, Nov 14, 2021 at 11:33 AM Peter Stephenson
> <p.w.stephenson@ntlworld.com> wrote:
> >
> > print has standard option syntax, so you need to terminate
> > lists of options (even if they're empty) with "--".
> 
> True statement but I think something else is going on here.
> 
> % set "--------" a b c
> % print $argv
> a b c
> 
> Zsh's generic option parser is consuming any number of consecutive
> hyphens as "--".  That's probably not right.

Yes, I think it's always done that --- I've noted it before but generally
thought changing it is more likely to cause than fix problems, but that
doesn't mean I'm right.

pws


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

end of thread, other threads:[~2021-11-15 16:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-14 19:19 print built-in doesn't print this jdh
2021-11-14 19:27 ` Norbert Zeh
2021-11-14 19:29 ` Peter Stephenson
2021-11-15  5:30   ` Mikael Magnusson
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

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