Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: triviality regarding $# counts




On 2024-04-13 12:45, Bart Schaefer wrote:
On Sat, Apr 13, 2024 at 11:08 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
But I'm still not happy with the dollars.  I had thought that "  $'...'  "  was grammatical but we have " ' ' "  -- meaning an empty line
There are three* forms of quoting:
Many thanks, it's a brief page of explanation like this that would feature in my imaginary 'Idiot's Guide to Shells'.  It's not the sort of information you can go looking for  when you don't know it because you don't even know what you're looking for.  It must be brought to your attention.
1) "X" -- expand variable references and other substitutions in X, but
do not split on $IFS **
2) 'X' -- do not do any expansions, X is literal
Those two I pretty much understand -- except IFS which I've learned not to touch.

3) $'X' -- interpret \n \t \e etc., but everything else is literal, as
is the final result
This is new to me.  Never used it.  Looks useful for strings.
This is all explained in the manual section "Quoting".  "typeset -p"
will output either no quoting at all, or #2, or #3,
I remember chafing over that some years back.
Note that because #3 is quoting, not substitution, it does not expand
inside #1.  Conversely, backticks `X` only look like quoting, they are
actually substitution equivalent to $(X) except without nesting, so
they do execute a command when appearing inside double quotes (#1).
Heavy.
* Four if you count using a backslash to protect a single following character.
Right.
** $@ and $ary[@] and ${(@)ary} get special handling, their array-ness
is preserved with each element quoted separately.
That needs pondering.
Let's look at your "redline" function:
...
So you probably should have written

redline () { echo -e "$red$*$nrm" }

because $* is the same as $@ except without that special
interpretation inside double quotes.
So, compared to the previous expansion, how would '$*' expand there?  I'm unclear as to the practical  difference.

Anyway .... when my typedef -p line showed those "   ' '    " with no dollar -- which seemed to me to forbid that "   $'...'  " grammar -- what I should read is that that element has nothing quoted ergo no 'controller' -- no expansion flag -- is needed.  Yes?  IOW the dollar might have been put there, but it has no work to do so is simply omitted.  Logical.  Do I have that right, for once?








Messages sorted by: Reverse Date, Date, Thread, Author