0

Here is the command I'm trying to escape a ' from bash, to vis' to ex-mode, and then back to bash so it can be read into the buffer again:

vi  -c 'sp | enew | read ! echo "Use to jump between missing categories ]\\\'"' /home/leeand00/Downloads/qfx/tmp3/converted_visaAccounts.20200619_193625.csv

The part that is giving me trouble is when I want to pass in read ! echo "Use jump between missing categories \\\'" that part always complains that there isn't a closing '; so how would one escape this?

  • Can you please trim your example? I think you are having no problems with the mark parts, so maybe you can eliminate those. Also, what exactly is your goal? Apparently you want to open an empty split and write Use to jump between missing categories ]' inside? – Quasímodo Aug 17 at 21:53
  • Also, have a look at this in man sh: "Enclosing characters in single quotes preserves the literal meaning of all the characters (except single quotes, making it impossible to put single-quotes in a single-quoted string)." – Quasímodo Aug 17 at 21:58
  • @Quasímodo Okay I removed the non-relevant portions. – leeand00 Aug 17 at 22:16
2

You can use '\'' to insert a literal single quote into a single-quoted string into the shell.

What this does is: close the currently-running single-quoted string with the first ', then insert an escaped single quote with \', then start a new single-quoted string with the last '.

It turns out that Ex will leave this single quote alone, and the read ! ... command won't mind it either since it's inside a double-quoted string itself, so it won't be handled in a special way either.

vi -c 'sp | enew | read ! echo "Use to jump between missing categories ]'\''"' /home/leeand00/Downloads/qfx/tmp3/converted_visaAccounts.20200619_193625.csv
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.