Xu Wang wrote (Sat 2017-Jun-24 13:12:03 -0400):

>     mutt -e 'push "l~f'"Jian"'\n"'

Note that this might not do what was expected, if your intention was
to make sure that Mutt would see the double quotation marks around
»Jian« (so »Jian« can contain spaces?).

Your shell will see the opening single quote character ' and read
exactly until the next such character, so it will see these five parts
(of which some are separated by spaces and some are not):

   mutt  -e  'push "l~f'  "Jian"  '\n"'

The double quotation marks around part 4 »Jian« will get dropped just
like the single quotation marks around parts 3 and 5 -- you might as
well get rid of them:

   $ echo 'push "l~f'"Jian"'\n"'
   push "l~fJian\n"

   $ echo 'push "l~f'Jian'\n"'
   push "l~fJian\n"

So in case of whitespace, Mutt should complain about the second part
not being a pattern:

   $ echo 'push "l~f'"Ji an"'\n"'
   push "l~fJi an\n"

A solution could be to drop the single quotation marks inside single
quotation marks (so the shell will see one part instead of parts 3,
4, and 5) plus escaping the inner double quotation marks so that
Mutt will read them as normal characters within the push command:

   $ echo 'push "l~f\"Ji  an\"\n"'
   push "l~f\"Ji  an\"\n"

Mutt will also accept single quotation marks in the <limit> pattern,
so if you create a shell command that will result in the following
string (using single quotation marks instead of escaped double
quotation marks), that should also work:

   push "l~f'Ji  an'\n"

Achieving that in a Bash is certainly possible, though not readable
for normal humans:

   $ echo 'push "l~f'"'"'Ji  an'"'"'\n"'

In any case, this will break again if you intend to use a variable
(instead of the fixed string »Jian«) whose value might not only
contain spaces but also quotation marks, which could confuse Mutt
while parsing the line; so using a generic approach might be best.
Maybe using Bash's builtin "printf" with its "%q" might help, but I
am not sure how Mutt reacts to backslash-escaped single quotes.

I would suggest asserting that the value neither contains quotation
marks nor spaces. :-)

Cheers, Marcus

-- 
   Marcus C. Gottwald  ·  <[email protected]>  ·  https://cheers.de


Reply via email to