{"id":38,"date":"2026-10-16T16:39:18","date_gmt":"2026-10-16T16:39:18","guid":{"rendered":"https:\/\/artisanal-dev.com\/?p=38"},"modified":"2026-10-16T16:39:18","modified_gmt":"2026-10-16T16:39:18","slug":"terminal-shebang","status":"publish","type":"post","link":"https:\/\/artisanal-dev.com\/index.php\/2026\/10\/16\/terminal-shebang\/","title":{"rendered":"Terminal Shebang #!"},"content":{"rendered":"<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Bash\" data-shcb-language-slug=\"bash\"><span><code class=\"hljs language-bash shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-meta\">#!\/bin\/bash<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\"><\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Bash<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">bash<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">If you&#8217;ve been in Linux\/Unix land long enough you understand that the shebang provides some unique uses for things like Python and bash. Here are some questions you may never have thought about.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How does the OS handle these lines?<br>What can you do with this line?<br>What possible problems could this line cause?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s start with the function of the shebang, it tells the kernel what application to run the script with. Let&#8217;s say we want to use something other than Bash?<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-meta\">#!\/usr\/bin\/tail -2<\/span>\n\njan\nfeb\nmarch<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This is a legitimate script. This tells the kernel to run the tail command and outputs the results as feb and march on their lines. Give it a try. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s consider what happens if  a different version \/bin\/bash is installed or even in a different directory? A better way to solve this would be to redirect the command through the environment. <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-meta\">#!\/usr\/bin\/env bash<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">This allows the system to search for the necessary bash that is assigned to the environment. If you have a newer user version rather than the system level one, you can make sure that it passes through the environment variables for the necessary bash. This also has implications for python.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.man7.org\/linux\/man-pages\/man1\/env.1.html\">https:\/\/www.man7.org\/linux\/man-pages\/man1\/env.1.html<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You should be aware of some edge cases for passing this command through the env. Each command is treated as a single line. The first example would have to account for this by adding the &#8216;-S&#8217; flag to the command. Otherwise, you will get an error message and wonder what&#8217;s going on.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-meta\">#!\/usr\/bin\/env -S tail -2<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p class=\"wp-block-paragraph\">There are other fun cool things you can do with the shebang and bash. I&#8217;ll take a deeper dive in future posts.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve been in Linux\/Unix land long enough you understand that the shebang provides some unique uses for things like Python and bash. Here are some questions you may never have thought about. How does the OS handle these lines?What can you do with this line?What possible problems could this line cause? Let&#8217;s start with [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[7],"class_list":["post-38","post","type-post","status-publish","format-standard","hentry","category-unix","tag-unix"],"_links":{"self":[{"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/posts\/38","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":8,"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":47,"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/posts\/38\/revisions\/47"}],"wp:attachment":[{"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artisanal-dev.com\/index.php\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}