2024-02-25 00:15:39Z (last updated 2024-07-31 02:02:49Z)
Here's a command. It will be run in the bash shell. What do you think this command will output?
for i in wh"y is" this a" thin'"''; do echo $i; done
All you have to worry about is how wh"y is" this a" thin'"''
will be split up by the shell. The rest of the command is just print each thing onto a new line, and what's considered "another argument" is up to the shell.
If you just got absolutely confused, don't worry, here's the output:
why is this a thin'
On why this is confusing: The command has single quotes and double quotes mixed together, added in the middle of words, and sometimes encapsulate no characters at all, making figuring out what's quoted and what's not quoted harder to figure out at a glance (especially without color highlighting).
Here's another command. What will this output?
echo \ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''\ ''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""\ ""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''""''
Well it's actually just the same as running echo. It'll give you an empty line.
That's because every quote here and new line as well has been reduced to nothing. There actually no contents in any of those quotes.
Those were just some ridiculous examples. Here's some more realistic examples that you may or may not need someday.
Let's say you're using single quotes to quote, and then you have to use a single quote within a single quote. Here's what it would look like for the sentence "Woody's wood":
echo 'Woody'\''s wood'
Here's the purpose of every apostrophe character in order:
echo '
)echo 'Woody'
)echo 'Woody'\'
)echo 'Woody'\''
)echo 'Woody'\''s wood'
)So the apostrophe quoting is closed, returning back to the shell interpretation of stuff, then an escaped apostrophe is used, and then the apostrophe quoting returns.
A more reasonable solution would be to use double quotes, but there are cases where you just have to use single quotes (apostrophes) because double quotes won't work.
=> public inbox (comments and discussions) | public inbox archives | (mailing list etiquette for public inbox) This content has been proxied by September (3851b).Proxy Information
text/gemini;lang=en