zsh-users
 help / color / mirror / code / Atom feed
From: "Mark J. Reed" <markjreed@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: triviality regarding $# counts
Date: Sun, 14 Apr 2024 11:11:30 -0400	[thread overview]
Message-ID: <CAA=-s3ybEOfWGew-LFg7gPpTg3=LsdTLoxmevzm2CkhY_KUHAw@mail.gmail.com> (raw)
In-Reply-To: <9e41a059-c051-4124-8296-48ccd97f793c@eastlink.ca>

[-- Attachment #1: Type: text/plain, Size: 1807 bytes --]

As I said about *echo* way back in my first response: the *print* command
is what is turning the backslash-n sequences into newlines. If you use *-r* to
turn off that behavior, you can see the strings unmangled:

% print -r $ggg

 abc\n \n def\n \n ghi\n


The -r is telling print not to do something it normally does. The result is
the raw string (which I think is what *-r* stands for).

To restate: if your goal is to print out a newline, you have options. If
you do this:

print $'\n'

Then you are creating in the shell's memory a string containing a literal
newline character (one byte with value 10), which the shell then passes to
*print*, which just echoes it verbatim, doing no translation on it
whatsoever.  Job done. The translation from \n to newline was done by the
shell before *print* ever ran.

If you instead do this:

print '\n'

Then the string you create and pass to *print* has no newline in it. It is
not one byte of value 10, but two bytes, one with value 92 (backslash) and
the second with value 110 (lowercase *n*).  The code implementing the
*print* command recognizes this sequence as code for "print a newline", so
it does. But that's the command doing that. The string itself has no
newline in it.



Mark J. Reed <markjreed@gmail.com>


On Sun, Apr 14, 2024 at 10:53 Ray Andrews <rayandrews@eastlink.ca> wrote:

>
>
> On 2024-04-14 07:15, Roman Perepelitsa wrote:
> > On Sun, Apr 14, 2024 at 4:06 PM Ray Andrews <rayandrews@eastlink.ca>
> wrote:
> >> % ggg=( 'abc\n' '\n' 'def\n' '\n' 'ghi\n' )
> > There are no newlines in there.
> % ggg=( ' abc\n' '\n' 'def\n' '\n' 'ghi\n' )
>
> % print $ggg
>   abc
>
>   def
>
>   ghi
>
>
> % typeset -p ggg
> typeset -a ggg=( ' abc\n' '\n' 'def\n' '\n' 'ghi\n' )
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 4423 bytes --]

  reply	other threads:[~2024-04-14 15:12 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  0:56 Ray Andrews
2024-04-12  4:55 ` Lawrence Velázquez
2024-04-12 14:48   ` Ray Andrews
2024-04-12 19:09     ` Bart Schaefer
2024-04-13  1:13       ` Ray Andrews
2024-04-13  1:33         ` Mark J. Reed
2024-04-13  2:28           ` Ray Andrews
2024-04-13  3:25             ` Lawrence Velázquez
2024-04-13 14:37               ` Ray Andrews
2024-04-13 15:14                 ` Ray Andrews
2024-04-13 17:19                   ` Mark J. Reed
2024-04-13 17:27                     ` Mark J. Reed
2024-04-13 18:08                       ` Ray Andrews
2024-04-13 19:45                         ` Bart Schaefer
2024-04-13 20:36                           ` Ray Andrews
2024-04-13 21:01                             ` Bart Schaefer
2024-04-14  0:28                               ` Ray Andrews
2024-04-14  0:30                               ` Lawrence Velázquez
2024-04-14  3:26                                 ` Ray Andrews
2024-04-14  3:49                                   ` Lawrence Velázquez
2024-04-14  4:57                                     ` Bart Schaefer
2024-04-14 13:24                                       ` Ray Andrews
2024-04-14 13:35                                         ` Roman Perepelitsa
2024-04-14 14:06                                           ` Ray Andrews
2024-04-14 14:15                                             ` Roman Perepelitsa
2024-04-14 14:53                                               ` Ray Andrews
2024-04-14 15:11                                                 ` Mark J. Reed [this message]
2024-04-14 16:23                                                   ` Ray Andrews
2024-04-14 14:06                                         ` Mark J. Reed
2024-04-14 14:47                                           ` Ray Andrews
2024-04-14 14:59                                             ` Mark J. Reed
2024-04-14 15:51                                         ` Bart Schaefer
2024-04-14 17:22                                           ` Ray Andrews
2024-04-14 17:42                                             ` Mark J. Reed
2024-04-14 18:24                                               ` Bart Schaefer
2024-04-14 22:00                                               ` Ray Andrews
2024-04-13 20:11                         ` Mark J. Reed
2024-04-13 20:53                   ` Bart Schaefer
2024-04-14  0:19                     ` Ray Andrews
2024-04-13  1:35         ` Bart Schaefer

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='CAA=-s3ybEOfWGew-LFg7gPpTg3=LsdTLoxmevzm2CkhY_KUHAw@mail.gmail.com' \
    --to=markjreed@gmail.com \
    --cc=rayandrews@eastlink.ca \
    --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).