{"id":20,"date":"2011-04-20T10:19:00","date_gmt":"2011-04-20T10:19:00","guid":{"rendered":"http:\/\/mattdturner.com\/wordpress\/?p=20"},"modified":"2011-04-26T11:29:48","modified_gmt":"2011-04-26T17:29:48","slug":"automatically-make-shell-scripts-executable","status":"publish","type":"post","link":"http:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/","title":{"rendered":"Automatically Make Shell Scripts Executable"},"content":{"rendered":"<p>I strongly believe that a script should be created to handle any repetitive process in the terminal.<\/p>\n<p>By default, when you create a new script, it does not have executable permissions. \u00a0So for each script that you create, you then have to chmod the file to be executable. \u00a0However, its kind of hypocrital to say that a script should be created to replace any repetitive process and then not figure out a way to automate the &#8216;chmod&#8217; command when creating a script.<\/p>\n<p>Well, as it turns out, a simple addition to your vimrc file will automatically make any newly created script an executable (so long as you have the &#8216;#!&#8217; in the file).<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">&quot; automatically give executable permissions if file begins with #!\u00a0\r\n&quot;and contains '\/bin\/' in the path\r\n\r\nau BufWritePost * if getline(1) =~ &quot;^#!&quot; | if getline(1) =~ &quot;\/bin\/&quot; | silent !chmod a+x  | endif | endif\r\nau BufWritePost * if getline(1) =~ &quot;^#!&quot; | if getline(1) =~ &quot;\/usr\/bin\/&quot; | silent !chmod a+x  | endif | endif<\/pre>\n<p>So just copy the above code into your .vimrc file (each uncommented line ends in 2 endif commands) and now you can create scripts that are executable by default.<\/p>\n<div class=\"zemanta-pixie\" style=\"margin-top: 10px; height: 15px;\"><a class=\"zemanta-pixie-a\" title=\"Enhanced by Zemanta\" href=\"http:\/\/www.zemanta.com\/\"><img decoding=\"async\" class=\"zemanta-pixie-img\" style=\"border: none; float: right;\" src=\"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27\" alt=\"Enhanced by Zemanta\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I strongly believe that a script should be created to handle any repetitive process in the terminal. By default, when you create a new script, it does not have executable permissions. \u00a0So for each script that you create, you then have to chmod the file to be executable. \u00a0However, its kind of hypocrital to say [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,20,21],"tags":[22,24,25,23,26,27],"class_list":["post-20","post","type-post","status-publish","format-standard","hentry","category-command-line","category-scripting","category-vim","tag-chmod","tag-filesystem-permissions","tag-script","tag-source-code","tag-vim-2","tag-vimrc","no-thumb"],"_links":{"self":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":3,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":48,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/20\/revisions\/48"}],"wp:attachment":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}