{"id":111,"date":"2006-12-23T09:08:58","date_gmt":"2006-12-23T17:08:58","guid":{"rendered":"http:\/\/messofpottage.com\/blog\/?p=111"},"modified":"2006-12-23T09:08:58","modified_gmt":"2006-12-23T17:08:58","slug":"the-whole-shebang","status":"publish","type":"post","link":"https:\/\/accretiondisc.com\/blog\/2006\/12\/23\/the-whole-shebang\/","title":{"rendered":"The whole shebang"},"content":{"rendered":"<p>For some reason the <a href=\"http:\/\/www.ubuntu.com\/\">Ubuntu<\/a> Linux distribution (or possibly Debian, on which it is based) doesn&#8217;t lie about <code>\/bin\/sh<\/code>. <a href=\"http:\/\/fedora.redhat.com\/\">Fedora<\/a> used to lie, and pretend that <code>\/bin\/bash<\/code> was <code>\/bin\/sh<\/code>. That way your stock <code>\/bin\/sh<\/code> still had <code>function<\/code>s and other post-<a href=\"http:\/\/www.ooblick.com\/text\/sh\/\">Version 7 Bourne Shell<\/a> features in your stock shell. But, as I say, Ubuntu doesn&#8217;t do that.<br \/>\n<!--more--><br \/>\nThe reason this matters is that I have a zillion shell scripts that begin with the standard <code>#!<\/code> <a href=\"http:\/\/en.wikipedia.org\/wiki\/Shebang_%28Unix%29\">shebang<\/a>-notation, and the shell I specify in them is <code>\/bin\/sh<\/code>. So now they&#8217;re all broken. (OK, maybe not <em>all<\/em>, but I tend to use functions a lot to simplify maintenance. Usually a shell script works for a year or two before breaking, and when that happens, it&#8217;s important that your scripts be simple to maintain. And for me, that means functions with obvious names instead of blocks of linear code.)<\/p>\n<p>Now you could argue that Fedora was wrong. So I should just fix the #! lines to use <code>\/bin\/bash<\/code> and go forward from there. Since I got rid of Fedora, this should be part of moving to Ubuntu. Suck it up and moveon.org, <em>que no<\/em>?<\/p>\n<p>But Fedora isn&#8217;t alone. Because <a href=\"http:\/\/www.apple.com\/macosx\/tiger\/\">Mac OS X<\/a> 10.3+ does the same thing. (Actually the mac does something even stranger: it puts two copies of <em><a href=\"http:\/\/www.gnu.org\/software\/bash\/\">bash<\/a><\/em> in <code>\/bin<\/code> and calls one of them <code>sh<\/code>. Have they ever heard of symlinks, or even hard links?).<\/p>\n<p>So I have two choices. I can fix things on Ubuntu and the mac by changing all the lines to be <code>\/bin\/bash<\/code>. But then what if I want to move to, say, HP-UX or Solaris, huh? So my other choice is to use <code>#!\/usr\/bin\/env bash<\/code> as my shebang line.<\/p>\n<p>The latter solution isn&#8217;t as efficient as the former, of course. I timed it on my mac and found it takes 6.88s to do a thousand shell-script invocations using <code>\/bin\/bash<\/code>, and 10.31s using <code>\/usr\/bin\/env<\/code>. Doing 10 takes 0.103s and 0.138s, so the ratio appears to be the same even for small values of <em>n<\/em>. Even if that .035s is constant below 10, I can wait 35\/1000 of a second each time I invoke a shell.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For some reason the Ubuntu Linux distribution (or possibly Debian, on which it is based) doesn&#8217;t lie about \/bin\/sh. Fedora used to lie, and pretend that \/bin\/bash was \/bin\/sh. That way your stock \/bin\/sh still had functions and other post-Version 7 Bourne Shell features in your stock shell. But, as I say, Ubuntu doesn&#8217;t do [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[52],"tags":[],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-technology"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paRqpr-1N","_links":{"self":[{"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":0,"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"wp:attachment":[{"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/accretiondisc.com\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}