4 ms·
Quoting and parsing continue to surprise people, and I don't blame them -- you're embedding one programming language inside another (regex inside bash), and the
by jrockway 6y ago
Quoting and parsing continue to surprise people, and I don't blame them -- you're embedding one programming language inside another (regex inside bash), and they use some of the same reserved symbols and have slightly different quoting rules. And, every language is "inspired" by the others, but have their own special rules, so the more you learn, the less sure of anything you'll ever be. (For example, '(' matches a literal parenthesis in Emacs Lisp regexes, and '\(' starts a capture group!)
For matching literal periods, I personally have gotten into the habit of using "[.]" instead of "\.". Less to go wrong in this double-embed scenario, and I have never ever regretted adding the extra byte to my regexp. (Of course, character classes have their own weirdness. Your editor that matches bracket paris will love the syntax for matching a literal '['.)
- userbinator 6y agoAs confusing as multi-layered escaping can be, I still vastly prefer the situation in Linux and other Unix-likes to that of Windows where each process is given nothing more than a mildly-processed command line from the shell (e.g. no globbing) as a string, and parses it however it wants to. Escaping in batch files is slightly different from interactive commands, each utility may have its own escaping conventions on top of those the shell has, etc. Linux and the like have a far more predictable and consistent experience, since argument splitting and globbing is always done once by the shell, and each process gets the already-split and expanded argument list.