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

Re: triviality regarding $# counts



On Sun, Apr 14, 2024 at 1:22 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
Hard spaces will be inside ticks or $'' . 
 
.. or double-quotes; don't forget about them.   " ", ' ', and $' ' are all literal spaces. It's other characters where the difference shows up. In "...", $-expansions still happen; in the others, they don't.  In $'...', ANSI C backslash escapes work; in the others, they don't.  Inside '...', absolutely everything is literal; there's not even a way to include a literal ' in the string. 

One thing about the shell that makes it different from other programming languages, however, is that the quotation marks themselves are not word delimiters.  So you can switch between types of quoted string... including entirely unquoted... without introducing a new shell "word".  That means all of these assignments store exactly the same thing in the variable x:

x=this\ is\ all\ one\ word
x="this is all one word"
x='this is all one word'
x=$'this is all one word'
x=this\ is' 'all" "one$' 'word

The ability to mix and match gives us the old way to get an apostrophe into an otherwise-single-quoted string: to close the quotes, add a backslashed apostrophe, and then go back into quotes:

x='That'\''s all, folks!'

But it's easier to just use ANSI quotes:

x=$'That\'s all, folks!'
 

--
Mark J. Reed <markjreed@xxxxxxxxx>


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