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