Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web.
|
2006-10-13 Why quoting in the Bourne shell makes me grumpyImagine for a moment that you have an almost arbitrary string (no nulls, newlines, or other funky control characters) that you want to quote so that it passes through the Bourne shell intact. How do you do it? The Bourne shell offers you two quoting schemes, strings in single quotes and strings in double quotes. Strings in double quotes need special characters escaped with backslashes. There are five of them (quick, do you know them all?), or six in some situations in some versions of the Bash manpage. And of course, backslash is not a general escaping character; putting it in front of a non-special character is not harmless. Strings in single quotes can't have anything escaped, which is OK, because nothing has special meaning inside them. Except a single quote. Since there is no way of escaping the single quote, you get to turn a single quote into five characters:
(Okay, I suppose you could turn it into (You may or may not be able to read that in your font, since a fair number of fonts are not so great at distinguishing single quotes, double quotes, and apostrophes. It's almost as bad as the great l vs 1 problem.) This leads to a general view of mine: often, the more quoting methods you have the worse off you are. Unless they are very specialized, quantity serves mostly to confuse, annoy, and surprise; you are better off with one method, ideally one as simple as possible. Sidebar: so how should shells do quoting?I'm glad you asked. Tom Duff's rc answered this question many years ago:
That's it. As a bonus it's dirt simple to write code that quotes a string for rc: double any single quotes, then put the whole thing in single quotes. (4 comments.)
programming/BourneQuoting written at 23:27:55; Add Comment
Link: Warning Signs for TomorrowWarning Signs for Tomorrow is a collection of warning signs for tomorrow. Amusing and potentially useful ones (for me; your mileage may vary) include 'lack of internet connectivity', 'ubiquitous surveillance', and 'motivation hazard'. (From James Nicoll.)
|
These are my WanderingThoughts GettingAround This is part of CSpace, and is written by ChrisSiebenmann. * * * Atom feeds are available; see the bottom of most pages. Categories: links, linux, programming, python, snark, solaris, spam, sysadmin, tech, unix, web |