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

Re: triviality regarding $# counts





On 2024-04-14 08:11, Mark J. Reed wrote:
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).

Ah!  Threw me off the scent there.  So print is ... yes I get it.  Ok, so that's what had me fooled.  So, one more thing and then I think I'll get back to straight and level:  How do we separate the elements?  I've always seen it with ticks.  Or ... now that I think ... with
$'...'
Yes? 

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.

Ok, that blows the fog away.  We have the 'real' newline, we have the string '\n' ... which print helpfully translates into the former.  Yes, if in doubt 'print -r'.

Sheesh, I fall into every pothole there could possibly be.





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