{"id":774,"date":"2014-10-22T17:25:41","date_gmt":"2014-10-22T17:25:41","guid":{"rendered":"http:\/\/shivdev.com\/blog\/?p=774"},"modified":"2015-03-11T19:21:25","modified_gmt":"2015-03-11T19:21:25","slug":"escape-quote-in-alias","status":"publish","type":"post","link":"http:\/\/shivdev.com\/blog\/2014\/10\/22\/escape-quote-in-alias\/","title":{"rendered":"Escape quote in alias"},"content":{"rendered":"<p>I wanted to create change the prompt to show the active git branch through an alias.<br \/>\nChanging PS1 as follows would do it as follows:<\/p>\n<blockquote><p>\n# Try this in bash to get the git prompt, but how do you alias this?<br \/>\nPS1='[\\u@\\h \\W$(__git_ps1 &#8221; (%s)&#8221;)]\\$\n<\/p><\/blockquote>\n<p>However I needed to create an alias for it and turns out that if you wanted to escape a single quote <strong>&#8216;<\/strong> you could do it using the following: &#8216;&#8221;&#8216;&#8221;&#8216;<\/p>\n<blockquote><p>\n# Note here that the entire aliased string needs to be escaped using a quote<br \/>\nalias ingit=&#8217;PS1='&#8221;&#8216;&#8221;&#8216;[\\u@\\h \\W$(__git_ps1 &#8221; (%s)&#8221;)]\\$'&#8221;&#8216;&#8221;&#8221;\n<\/p><\/blockquote>\n<p>Now I can activate the git prompt that I need through an alias that contains a combination of single and double quotes.<\/p>\n<p>Now !!! I wanted to change the IP Address of my DHCP vm in the \/etc\/hosts file. (<a href=\"http:\/\/shivdev.com\/blog\/2015\/03\/11\/sed-1-etchosts-extra-characters-at-the-end-of-h-command\/\">Related sed Article<\/a>)<\/p>\n<blockquote><p>\n# something that works<br \/>\n$ sed -i &#8221; &#8216;s\/^192.168.*vm\/192.168.1.12 vm\/&#8217; \/etc\/hosts<\/p>\n<p># i would like to do something like this<br \/>\n$ setvmip 192.168.1.12<\/p>\n<p># so the escaped version is<br \/>\nalias setvmip=&#8217;function _setvmip(){ sudo sed -i &#8220;&#8221; &#8216;&#8221;&#8216;&#8221;&#8216;s\/^192.168.*vm\/'&#8221;&#8216;&#8221;&#8216;$@'&#8221;&#8216;&#8221;&#8216; vm\/'&#8221;&#8216;&#8221;&#8216; \/etc\/hosts ; }; _setvmip&#8217;<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I wanted to create change the prompt to show the active git branch through an alias. Changing PS1 as follows would do it as follows: # Try this in bash to get the git prompt, but how do you alias this? PS1='[\\u@\\h \\W$(__git_ps1 &#8221; (%s)&#8221;)]\\$ However I needed to create an alias for it and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[],"_links":{"self":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/774"}],"collection":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/comments?post=774"}],"version-history":[{"count":6,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/774\/revisions"}],"predecessor-version":[{"id":834,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/posts\/774\/revisions\/834"}],"wp:attachment":[{"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/media?parent=774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/categories?post=774"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shivdev.com\/blog\/wp-json\/wp\/v2\/tags?post=774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}