{"id":444,"date":"2020-10-21T02:50:00","date_gmt":"2020-10-21T06:50:00","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=444"},"modified":"2021-01-01T00:55:08","modified_gmt":"2021-01-01T05:55:08","slug":"bash-how-to-escape-single-quotes-single-quotes","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/bash-how-to-escape-single-quotes-single-quotes\/","title":{"rendered":"bash: How to escape single quotes single quotes"},"content":{"rendered":"\n<p>In bash, you can use the backslash character (&#8220;\\&#8221;) to escape any character. However, if a single quote is inside single quotes, it cannot be escaped with a backslash character. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias ycd='some_command'<\/code><\/pre>\n\n\n\n<p>works fine but<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias ycd='command -option 'something''\nalias ycd='command -option \\'something\\''<\/code><\/pre>\n\n\n\n<p>both of the above return errors.<\/p>\n\n\n\n<p>A trick around this problem is to use both quotes i.e. use double quotes to surround the single quote and single quotes again to surround the single quote.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using ' is that same as '\"'\"'<\/code><\/pre>\n\n\n\n<p>To rewrite the example above&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>alias ycd='command -option '\"'\"'something'\"'\"''<\/code><\/pre>\n\n\n\n<p>Note that the first and last single quotes are not converted.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In bash, you can use the backslash character (&#8220;\\&#8221;) to escape any character. However, if a single quote is inside single quotes, it cannot be escaped with a backslash character. For example: works fine but both of the above return errors. A trick around this problem is to use both quotes i.e. use double quotes [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":493,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101,34],"tags":[94,35],"class_list":["post-444","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bash","category-linux","tag-bash","tag-linux"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/444","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=444"}],"version-history":[{"count":1,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/444\/revisions"}],"predecessor-version":[{"id":445,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/444\/revisions\/445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media\/493"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}