{"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"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Automatically Make Shell Scripts Executable - Tech N Comp<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Automatically Make Shell Scripts Executable - Tech N Comp\" \/>\n<meta property=\"og:description\" content=\"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;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech N Comp\" \/>\n<meta property=\"article:published_time\" content=\"2011-04-20T10:19:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-04-26T17:29:48+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27\" \/>\n<meta name=\"author\" content=\"Admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/\"},\"author\":{\"name\":\"Admin\",\"@id\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/ddfa8276a3c382cc0a217b9cba226f28\"},\"headline\":\"Automatically Make Shell Scripts Executable\",\"datePublished\":\"2011-04-20T10:19:00+00:00\",\"dateModified\":\"2011-04-26T17:29:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/\"},\"wordCount\":202,\"commentCount\":5,\"image\":{\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/img.zemanta.com\\\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27\",\"keywords\":[\"Chmod\",\"Filesystem permissions\",\"script\",\"Source code\",\"vim\",\"vimrc\"],\"articleSection\":[\"Command Line\",\"Scripting\",\"Vim\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/\",\"url\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/\",\"name\":\"Automatically Make Shell Scripts Executable - Tech N Comp\",\"isPartOf\":{\"@id\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/img.zemanta.com\\\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27\",\"datePublished\":\"2011-04-20T10:19:00+00:00\",\"dateModified\":\"2011-04-26T17:29:48+00:00\",\"author\":{\"@id\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/ddfa8276a3c382cc0a217b9cba226f28\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/mattdturner.com\\\/wordpress\\\/2011\\\/04\\\/automatically-make-shell-scripts-executable\\\/#primaryimage\",\"url\":\"http:\\\/\\\/img.zemanta.com\\\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27\",\"contentUrl\":\"http:\\\/\\\/img.zemanta.com\\\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27\"},{\"@type\":\"WebSite\",\"@id\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/#website\",\"url\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/\",\"name\":\"Tech N Comp\",\"description\":\"The one stop shop for everything Technology and Computer Related\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\\\/\\\/mattdturner.com\\\/wordpress\\\/#\\\/schema\\\/person\\\/ddfa8276a3c382cc0a217b9cba226f28\",\"name\":\"Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f908010f32d1c51d493f0c45d4ecaadcc12862723680f7d4ff73e7619d611855?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f908010f32d1c51d493f0c45d4ecaadcc12862723680f7d4ff73e7619d611855?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/f908010f32d1c51d493f0c45d4ecaadcc12862723680f7d4ff73e7619d611855?s=96&r=g\",\"caption\":\"Admin\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Automatically Make Shell Scripts Executable - Tech N Comp","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/","og_locale":"en_US","og_type":"article","og_title":"Automatically Make Shell Scripts Executable - Tech N Comp","og_description":"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;]","og_url":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/","og_site_name":"Tech N Comp","article_published_time":"2011-04-20T10:19:00+00:00","article_modified_time":"2011-04-26T17:29:48+00:00","og_image":[{"url":"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27","type":"","width":"","height":""}],"author":"Admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Admin","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/#article","isPartOf":{"@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/"},"author":{"name":"Admin","@id":"http:\/\/mattdturner.com\/wordpress\/#\/schema\/person\/ddfa8276a3c382cc0a217b9cba226f28"},"headline":"Automatically Make Shell Scripts Executable","datePublished":"2011-04-20T10:19:00+00:00","dateModified":"2011-04-26T17:29:48+00:00","mainEntityOfPage":{"@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/"},"wordCount":202,"commentCount":5,"image":{"@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/#primaryimage"},"thumbnailUrl":"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27","keywords":["Chmod","Filesystem permissions","script","Source code","vim","vimrc"],"articleSection":["Command Line","Scripting","Vim"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/","url":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/","name":"Automatically Make Shell Scripts Executable - Tech N Comp","isPartOf":{"@id":"http:\/\/mattdturner.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/#primaryimage"},"image":{"@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/#primaryimage"},"thumbnailUrl":"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27","datePublished":"2011-04-20T10:19:00+00:00","dateModified":"2011-04-26T17:29:48+00:00","author":{"@id":"http:\/\/mattdturner.com\/wordpress\/#\/schema\/person\/ddfa8276a3c382cc0a217b9cba226f28"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/mattdturner.com\/wordpress\/2011\/04\/automatically-make-shell-scripts-executable\/#primaryimage","url":"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27","contentUrl":"http:\/\/img.zemanta.com\/zemified_e.png?x-id=4ed850ae-cb9b-4fc2-b46e-9965e1835b27"},{"@type":"WebSite","@id":"http:\/\/mattdturner.com\/wordpress\/#website","url":"http:\/\/mattdturner.com\/wordpress\/","name":"Tech N Comp","description":"The one stop shop for everything Technology and Computer Related","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/mattdturner.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/mattdturner.com\/wordpress\/#\/schema\/person\/ddfa8276a3c382cc0a217b9cba226f28","name":"Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/f908010f32d1c51d493f0c45d4ecaadcc12862723680f7d4ff73e7619d611855?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f908010f32d1c51d493f0c45d4ecaadcc12862723680f7d4ff73e7619d611855?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f908010f32d1c51d493f0c45d4ecaadcc12862723680f7d4ff73e7619d611855?s=96&r=g","caption":"Admin"}}]}},"_links":{"self":[{"href":"http:\/\/mattdturner.com\/wordpress\/wp-json\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"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}]}}