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

Re: tilde syntax




On 2024-01-05 16:23, Bart Schaefer wrote:
But that's just it: The base case in zsh is that if you CAN see it
(and you don't see quotes around it) then it IS active, and if you
CAN'T see it (or you do see quotes) then it's literal.  The only time
you need to get fancy is when you've deliberately hidden something
("inside" a parameter) and you need to expose it.  In most shells
other than zsh the patterns are active whether you can see them or
not, unless you see quotes, which means you see a lot of quotes.  The
corollary to the base case is that parameter references expand in
double quotes but not in single quotes, but expanding does not mean
making the contents active.
I'm going to save that and reread it a few times.  Much has been made clear, more will come.

      
"One of the endless problems with zsh -- or any other shell -- is that there are places where entered characters are presumed to be literal -- but can be forced to indicate some action or command -- and other places where entered characters are presumed to be actions -- but can be forced to become literal characters."
That's close to a complete mischaracterization.  Or conversely, it's
true of every programming language, just with differences of syntax.

I never had a problem in C -- what's literal is always transparent.  Maybe at your level of understanding it's true of zsh as well but at my level what I said is exactly how it seems.  Mind, C constructions are trivially simple compared to shell.  Actually given the awesome power I'm quite astonished that parsing works as effectively as it does.

...

Na ... I see it.  What's quoted is literal and params are literal unless the tilde is used.  And quotes seem to 'cancel' the tilde, which is logical:

asterisk='*'
echo $asterisk      # Params are literal unless tilde is used
echo "$asterisk"    # Quotes here have no work to do, it's already literal
echo $~asterisk    # Param with tilde is expanded.
echo "$~asterisk"    # Quotes here seem to neutralize the tilde, which strikes me as just fine. Outermost control has the final say.

Output:

1 /aWorking/Zsh/Source/Wk/9 1 % . ../test1
*
*
1 2 3 4 5
*

Maybe, finally, it really is simple :-) 

Oh, but then there's substitutions where ${ .../.../}  and so on involve literals but that kind of thing is special to the 'internal grammar' of the particular substitution.

Thanks Bart, you've been patient as always.  I understand it well enough, let's let it drop I've wasted enough of your time.




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