{"id":319228,"date":"2022-02-03T00:02:49","date_gmt":"2022-02-03T08:02:49","guid":{"rendered":"https:\/\/dreness.com\/blog\/?p=319228"},"modified":"2022-02-03T00:02:51","modified_gmt":"2022-02-03T08:02:51","slug":"splashguard-of-departure","status":"publish","type":"post","link":"https:\/\/dreness.com\/blog\/archives\/319228","title":{"rendered":"Splashguard of Departure"},"content":{"rendered":"\n<p>Trivia question: what kind of protection should you wear when calling <code>diff<\/code> from a Shortcuts.app &#8220;Run Shell Script&#8221; action?<\/p>\n\n\n\n<p>You should affix the Splashguard of Departure, ideally with some +charisma to offset the posix misalignment. This is because &#8220;Run Shell Script&#8221; actions are executed with an implicit <code>set -e<\/code>. I&#8217;ll elaborate.<\/p>\n\n\n\n<p><code>set -e<\/code> means the script (and by extension, the whole shortcut) is halted whenever any of the commands executed in the script exit non-zero. It is customary for tools of the posix persuasion to set their exit status to zero upon success and non-zero upon failure. The trick with common but not mandatory behaviors is that the exceptions tend to sting. <code>diff<\/code> and a few of its siblings are exceptional in this regard, although you wouldn&#8217;t learn about that directly from the <code>diff<\/code> man page. Instead, you have to accept the challenge found at the bottom of the <code>diff<\/code> man page:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">The full documentation for diff is maintained as a Texinfo manual.&nbsp; If the info and diff programs are properly installed at your site, the command\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; info diff\nshould give you access to the complete manual.<\/pre>\n\n\n\n<p>Respect to elders notwithstanding, Texinfo is a total train wreck every time I try to use it, so please accept this shortcut:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">andre@boom ~ % info diff 2&gt; \/dev\/null | grep -A 1 'exit status of'\n   An exit status of 0 means no differences were found, 1 means some\ndifferences were found, and 2 means trouble.\n--\n   An exit status of 0 means no differences were found, 1 means some\ndifferences were found, and 2 means trouble.\n--\n   An exit status of 0 means `diff3' was successful, 1 means some\nconflicts were found, and 2 means trouble.\n--\n   An exit status of 0 means no differences were found, 1 means some\ndifferences were found, and 2 means trouble.<\/pre>\n\n\n\n<p>For example, in <a href=\"https:\/\/www.icloud.com\/shortcuts\/22f9f374b7264fceb14a39666f049567\">this shortcut<\/a>, the first action completes because <code>diff<\/code> exits zero, but the second action causes the shortcut to fail with <code>Exit code: 1<\/code>. If it&#8217;s a big script, it might even take you a while to pinpoint the problem.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/containment-breach.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"798\" src=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/containment-breach-1024x798.png\" alt=\"\" class=\"wp-image-320184\" srcset=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/containment-breach-1024x798.png 1024w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/containment-breach-300x234.png 300w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/containment-breach-1536x1197.png 1536w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/containment-breach.png 1724w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>Normally I would run <code>newproc.d<\/code> to monitor command executions in real time, but that requires disabling SIP, which I usually have <em>enabled<\/em> these days due to <a href=\"https:\/\/twitter.com\/GuacamoleQueen\/status\/1463277197028847619\">this unfortunate constraint<\/a>. I don&#8217;t know if <code>newproc.d<\/code> would have been the last place I had to look, but I suspect it would have.<\/p>\n\n\n\n<p>Instead I turned to <code><a href=\"http:\/\/newosxbook.com\/tools\/supraudit.html\">supraudit<\/a><\/code> which does show all the commands executed from the script &#8211; EXCEPT the one that fails the whole shortcut, which is probably a clue if you&#8217;re looking closely enough. Console logs are mostly useless in this case without &#8216;<a href=\"https:\/\/www.cmdsec.com\/unified-logs-enable-private-data\/?utm_source=share&amp;utm_medium=ios_app&amp;utm_name=iossmf\">private data<\/a>&#8216;, which is inconvenient to get &#8211; for your protection, of course. I eventually found the culprit by testing progressively smaller scripts until <code>diff<\/code> alone was causing failures.<\/p>\n\n\n\n<p>Right then, the remedy: Splashguard of Departure is easily crafted from two ingots and one eternal truth. Its magical effects include the formation of a specialized tribunal that serves to contain the representations of <code>diff<\/code>\u2019s quality of departure that are not tolerated in this locale. In the <a href=\"https:\/\/www.icloud.com\/shortcuts\/85841423d1ef4886af8428e6a5a4c711\">following example<\/a>, eternal truth (i.e. <code>\/bin\/true<\/code>) is replaced with a small placard which works just as well.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/splashguard-of-departure-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"884\" src=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/splashguard-of-departure-1-1024x884.png\" alt=\"\" class=\"wp-image-320185\" srcset=\"https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/splashguard-of-departure-1-1024x884.png 1024w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/splashguard-of-departure-1-300x259.png 300w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/splashguard-of-departure-1-1536x1326.png 1536w, https:\/\/dreness.com\/blog\/wp-content\/uploads\/2022\/02\/splashguard-of-departure-1.png 1724w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Trivia question: what kind of protection should you wear when calling diff from a Shortcuts.app &#8220;Run Shell Script&#8221; action? You should affix the Splashguard of Departure, ideally with some +charisma to offset the posix misalignment. This is because &#8220;Run Shell &hellip; <a href=\"https:\/\/dreness.com\/blog\/archives\/319228\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,14,6],"tags":[],"class_list":["post-319228","post","type-post","status-publish","format-standard","hentry","category-development","category-os-x","category-pro-tip","category-scripts"],"_links":{"self":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/319228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/comments?post=319228"}],"version-history":[{"count":6,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/319228\/revisions"}],"predecessor-version":[{"id":320186,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/posts\/319228\/revisions\/320186"}],"wp:attachment":[{"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/media?parent=319228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/categories?post=319228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dreness.com\/blog\/wp-json\/wp\/v2\/tags?post=319228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}