zsh-users
 help / color / mirror / code / Atom feed
From: "Lawrence Velázquez" <larryv@zsh.org>
To: zsh-users@zsh.org
Subject: Re: triviality regarding $# counts
Date: Sat, 13 Apr 2024 20:30:16 -0400	[thread overview]
Message-ID: <c03f0402-6df1-4ca5-a32a-3840e1573595@app.fastmail.com> (raw)
In-Reply-To: <CAH+w=7bf07RN+vmzE6cnLLrg4Kh+1ziauxiEzanHHUh5xddMMA@mail.gmail.com>

On Sat, Apr 13, 2024, at 5:01 PM, Bart Schaefer wrote:
> On Sat, Apr 13, 2024 at 1:36 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>>
>> On 2024-04-13 12:45, Bart Schaefer wrote:
>> > redline () { echo -e "$red$*$nrm" }
>> >
>> So, compared to the previous expansion, how would '$*' expand there?
>
> redline a b c
>
> would mean
>
> echo -e "$red$1 $2 $3$nrm"
>
> One word, with two quoted spaces, instead of three words.
>
>> I'm unclear as to the practical  difference.
>
> For "echo" it doesn't matter because echo is also going to paste its
> arguments together, but it might matter to some other command.

A different output method should make this clearer:

	% f1() { printf '<%s>' "x$@x"; echo; }
	% f2() { printf '<%s>' "x$*x"; echo; }
	% f1 a b c
	<xa><b><cx>
	% f2 a b c
	<xa b cx>

The command "printf '<%s>' ..." outputs each argument enclosed in
"<...>" (other than the format string itself).  Observe that
double-quoted $@ can expand to multiple words, while double-quoted
$* always expands to one.

This actually makes a difference to nearly every command you might
think of, with "echo" being a rare exception (and even then, only
when the first character of IFS is a space).

	% arr=(.zshenv .zprofile .zshrc)
	% set -x
	% wc -c "$arr[@]"
	+zsh:44> wc -c .zshenv .zprofile .zshrc
	    1063 .zshenv
	    1023 .zprofile
	    3807 .zshrc
	    5893 total
	% wc -c "$arr[*]"
	+zsh:45> wc -c '.zshenv .zprofile .zshrc'
	wc: .zshenv .zprofile .zshrc: open: No such file or directory


-- 
vq


  parent reply	other threads:[~2024-04-14  0:33 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 [this message]
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
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=c03f0402-6df1-4ca5-a32a-3840e1573595@app.fastmail.com \
    --to=larryv@zsh.org \
    --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).