How to Paste Text in Linux Terminal Safely
There are three errors in the following code snippet:
xxxxxxxxxx
grep –color=always “some pattern” ./𝘮𝘪𝘥𝘥𝘭𝘦
These and other errors are common on the web, but can come from anywhere. Sometimes they are caused by user ignorance and other times by the platform itself. Can you tell what the issues are? In order of their appearance:
The funny–looking horizontal line before
color
is not a double dash, and not even a single dash, but rather an en dash. WYSIWYG tools often convert double dashes to en dashes automatically. But en dashes are not used to prefix options, so the whole word is going to be treated as a pattern and the rest of the arguments will be treated as paths, leading to a confusing result:xxxxxxxxxx
$ grep –color=always “some pattern” ./middle
grep: “some: No such file or directory
grep: pattern”: No such file or directory
grep: ./middle: No such file or directory
As you can see from the error message above, the quotes around
some pattern
are not syntactic. That is, instead of marking the start and end of the filename they are treated as part of the filename. That is because they are typographic quotes, another piece of common automatic formatting by WYSIWYG tools. And since there are no syntactic quotes that part of the command is split into words.The string
middle
is slanted or italicized, which hints at the problem for anyone familiar with Markdown and similar formats. These formats are sent through a preprocessor program to produce HTML. And a common way to produce italicized text in the resulting HTML is to surround the text with asterisks, which we know as globbing characters!
So the original command was probably something like this:
xxxxxxxxxx
grep --color=always "pattern" ./*middle*
“Probably” is the best we can do without more information. Although the typographic characters would normally set off alarms they could of course be intentional. And the text which resulted in 𝘮𝘪𝘥𝘥𝘭𝘦
could also be from any other common italicization such as _middle_
or /middle/
.
Copy/paste exploit#
This lesson preview is part of the The newline Guide to Bash Scripting course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.
Get unlimited access to The newline Guide to Bash Scripting, plus 70+ \newline books, guides and courses with the \newline Pro subscription.
