<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>RSS Feed for sh - James Stone&apos;s Blog</title><description>Blog posts tagged with sh</description><link>https://jamesst.one/</link><item><title>Find sqlite dbs</title><link>https://jamesst.one/posts/finding-sqlite-dbs/</link><guid isPermaLink="true">https://jamesst.one/posts/finding-sqlite-dbs/</guid><description>&lt;![CDATA[&lt;p&gt;Lots of applications use sqlite dbs. It can be useful to try and find them all. For this you can use the following command&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;find . -type f -exec sh -c &apos;head -c 16 &quot;$1&quot; 2&gt;/dev/null | grep -q &quot;^SQLite format&quot; &amp;#x26;&amp;#x26; echo &quot;$1&quot;&apos; _ {} \;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;as all sqlite files start with the header string: “SQLite format 3\000” , see: &lt;a href=&quot;https://www.sqlite.org/fileformat.html&quot;&gt;Database File Format&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;it can then be helpful to get the size of each result&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;find . -type f -exec sh -c &apos;head -c 16 &quot;$1&quot; 2&gt;/dev/null | grep -q &quot;^SQLite format&quot; &amp;#x26;&amp;#x26; echo &quot;$1 $(stat -c%s &quot;$1&quot; | numfmt --to=iec)&quot;&apos; _ {} \;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;]]&gt;</description><pubDate>Mon, 25 Nov 2024 00:00:00 GMT</pubDate></item><item><title>Adding auto complete in bash</title><link>https://jamesst.one/posts/auto-completion/</link><guid isPermaLink="true">https://jamesst.one/posts/auto-completion/</guid><description>&lt;![CDATA[&lt;p&gt;in bash code completions are setup using the &lt;code&gt;complete &lt;/code&gt;command&lt;/p&gt;
&lt;p&gt;you can print all current system &lt;code&gt;completion&lt;/code&gt; s using &lt;code&gt;complete -p&lt;/code&gt;&lt;/p&gt;]]&gt;</description><pubDate>Thu, 29 Aug 2024 00:00:00 GMT</pubDate></item><item><title>Interactively debug a sh script</title><link>https://jamesst.one/posts/debugging-sh-scripts/</link><guid isPermaLink="true">https://jamesst.one/posts/debugging-sh-scripts/</guid><description>&lt;![CDATA[&lt;p&gt;My common (ba)sh script setup is a bit like this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# By default, in a pipeline of commands, the exit status of the pipeline is determined by&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# the exit status of the last command in the pipeline. This changes that to fail if any command fails&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -o&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; pipefail&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# stop on exit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -o&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; errexit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# trace , print all commands before running.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Another approach that I just thought of that is useful is to enter an interactive shell should a command fail. eg&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;may_fail&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; bash&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is particularly useful when in a loop and subshell:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;find&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;$root_directory&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -type&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; while&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; read&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -r&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; dir&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;    {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;      cd&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;$dir&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;      may_fail&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; bash&lt;/span&gt;&lt;span style=&quot;color:#6A737D&quot;&gt; # explore current state if this fails.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;done&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It allows the loop to pause until you’re ready to continue by pressing &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;d&lt;/kbd&gt;, or you can exit entirely using &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;c&lt;/kbd&gt;.&lt;/p&gt;]]&gt;</description><pubDate>Wed, 16 Aug 2023 00:00:00 GMT</pubDate></item></channel></rss>