<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ian Pride</title>
    <description>The latest articles on DEV Community by Ian Pride (@thefluxapex).</description>
    <link>https://dev.to/thefluxapex</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F192199%2F52a7649b-1892-4cfe-9d61-111b8f621bae.jpeg</url>
      <title>DEV Community: Ian Pride</title>
      <link>https://dev.to/thefluxapex</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thefluxapex"/>
    <language>en</language>
    <item>
      <title>Shell Pipe Wrapper Functions</title>
      <dc:creator>Ian Pride</dc:creator>
      <pubDate>Sun, 07 Feb 2021 23:32:38 +0000</pubDate>
      <link>https://dev.to/thefluxapex/shell-pipe-wrapper-functions-d6</link>
      <guid>https://dev.to/thefluxapex/shell-pipe-wrapper-functions-d6</guid>
      <description>&lt;h1&gt;
  
  
  Shell Pipe Wrapper Functions
&lt;/h1&gt;

&lt;p&gt;Create pipe functions from any builtin command, function, or executable program in the Linux shell.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Shell Pipe Wrapper Functions

&lt;ul&gt;
&lt;li&gt;Disclaimer&lt;/li&gt;
&lt;li&gt;Piping Output In The Linux Command Line&lt;/li&gt;
&lt;li&gt;Pipe Efficiency&lt;/li&gt;
&lt;li&gt;Pipe Availability&lt;/li&gt;
&lt;li&gt;Pipe Wrapper Functions&lt;/li&gt;
&lt;li&gt;Pipe Wrapper Logic&lt;/li&gt;
&lt;li&gt;Examples&lt;/li&gt;
&lt;li&gt;
Pipe Wrapper Function Simple Example

&lt;ul&gt;
&lt;li&gt;Simple Example STAT Program&lt;/li&gt;
&lt;li&gt;STAT Program Function Wrapper&lt;/li&gt;
&lt;li&gt;STAT Program Function Example&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
Pipe Wrapper Function Advanced Example

&lt;ul&gt;
&lt;li&gt;Advanced Example RM Program&lt;/li&gt;
&lt;li&gt;RM Program Function Wrapper&lt;/li&gt;
&lt;li&gt;RM Program Function Example&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disclaimer
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nwJsFoU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/static/v1.svg%3Flabel%3DSkill%26message%3DIntermediate%26color%3Dffc40d" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nwJsFoU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/static/v1.svg%3Flabel%3DSkill%26message%3DIntermediate%26color%3Dffc40d" alt="Intermediate" width="114" height="20"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ubMCfjz7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/static/v1.svg%3Flabel%3DBut%26message%3DBeginner%2520Friendly%26color%3D00a300" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ubMCfjz7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.shields.io/static/v1.svg%3Flabel%3DBut%26message%3DBeginner%2520Friendly%26color%3D00a300" alt="Beginner Friendly" width="136" height="20"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those who mention &lt;code&gt;xargs&lt;/code&gt;this an alternative method that makes extra logic processing simpler... And I don't like using &lt;code&gt;xargs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This post assumes that you are familiar with the Linux command line, commands, shell functions, std(in|out), and piping but it should not be too difficult to understand if you are new.&lt;/p&gt;

&lt;h2&gt;
  
  
  Piping Output In The Linux Command Line
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Pipe Efficiency
&lt;/h3&gt;

&lt;p&gt;Piping output is not always the best or fastest way to do things and sometimes can be quite redundant if the command in question has it's own methods of processing output (e.g. &lt;code&gt;find -exec {} \;&lt;/code&gt;) as each part of a pipeline is a subshell, but for many things this inefficiency is negligible and sometimes a pipe is almost necessary or, at least, the best way to process output.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pipe Availability
&lt;/h3&gt;

&lt;p&gt;We all have more than likely used a pipe &lt;code&gt;|&lt;/code&gt; in the Linux shell environment to pipe stdout to another builtin command, function, or executable and eventually we realize that not everything can be piped to.&lt;/p&gt;

&lt;p&gt;In order to pipe output to a command the command must process &lt;code&gt;stdin&lt;/code&gt; (as you would user input) and not all programs do so.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipe Wrapper Functions
&lt;/h2&gt;

&lt;p&gt;In this post I will show you how I write a sort of &lt;em&gt;generic&lt;/em&gt; shell function for any command, function, or binary file program that doesn't already process stdin and can be used almost completely in place of or with the original command.&lt;/p&gt;

&lt;p&gt;This will not be a 100% tutorial, but the examples will have &lt;code&gt;documenting comments&lt;/code&gt; and I will explain as I go along.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pipe Wrapper Logic
&lt;/h3&gt;

&lt;p&gt;The basic logic is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Test if the file descriptor (&lt;code&gt;FD&lt;/code&gt;) is greater than 0 (check if there is stdin already in the piped subshell):

&lt;ol&gt;
&lt;li&gt;Process the input in whatever way, usually &lt;code&gt;while&lt;/code&gt; reading the input passing the input with pass arguments to the command, function, or file.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;If the function has not (&lt;code&gt;else&lt;/code&gt;) received &lt;code&gt;stdin&lt;/code&gt;:

&lt;ol&gt;
&lt;li&gt;Only pass arguments to the command, function, or file.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Examples
&lt;/h2&gt;

&lt;p&gt;These examples all share the same simple construct/concept while only varying on logic that we need inside the &lt;code&gt;if [ ! -t 0 ]; then&lt;/code&gt; block and more often than not, only in the &lt;code&gt;while&lt;/code&gt; block.&lt;/p&gt;

&lt;p&gt;Most of the time we will only need the basics of what is written here and not extra logic/expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;command_pipe &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;local &lt;/span&gt;input
        &lt;span class="c"&gt;# input logic here&lt;/span&gt;
        &lt;span class="c"&gt;# while read or otherwise to create $input&lt;/span&gt;
        &lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;else
        &lt;/span&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pipe Wrapper Function Simple Example
&lt;/h3&gt;

&lt;p&gt;Most common usage.&lt;/p&gt;

&lt;h4&gt;
  
  
  Simple Example STAT Program
&lt;/h4&gt;

&lt;p&gt;This wraps the &lt;code&gt;stat&lt;/code&gt; command to be able to accept standard input, especially from the &lt;code&gt;stdout&lt;/code&gt; of a &lt;em&gt;piped&lt;/em&gt; command at the same time allowing you to still pass normal arguments to the command. &lt;/p&gt;

&lt;h5&gt;
  
  
  STAT Program Function Wrapper
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;stat_pipe &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 0 &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="c"&gt;# Test if there is input&lt;/span&gt;
        &lt;span class="nb"&gt;local &lt;/span&gt;input
        &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; input&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="c"&gt;# read each input &lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;  &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="c"&gt;# this is extra logic&lt;/span&gt;
                &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="c"&gt;# more extra logic&lt;/span&gt;
                &lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;# process input with command and arguments&lt;/span&gt;
            &lt;span class="k"&gt;fi
        done
    else &lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;fi&lt;/span&gt; &lt;span class="c"&gt;# if no input then run the command as usual with arguments&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  STAT Program Function Example
&lt;/h5&gt;

&lt;p&gt;Print my &lt;code&gt;.bash_func&lt;/code&gt; files and get the file sizes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; .bash_func&lt;span class="k"&gt;*&lt;/span&gt;
.bash_funcs
.bash_funcs_nocomments
.bash_funcs.old
 &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; .bash_func&lt;span class="k"&gt;*&lt;/span&gt; | stat_pipe &lt;span class="nt"&gt;-c&lt;/span&gt; %s
90329
53140
59990
 &lt;span class="nv"&gt;$ &lt;/span&gt;stat_pipe &lt;span class="nt"&gt;-c&lt;/span&gt; %s .bash_func&lt;span class="k"&gt;*&lt;/span&gt;
90329
53140
59990
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Pipe Wrapper Function Advanced Example
&lt;/h3&gt;

&lt;p&gt;Something a little more advanced.&lt;/p&gt;

&lt;h4&gt;
  
  
  Advanced Example RM Program
&lt;/h4&gt;

&lt;p&gt;A wrapper for the &lt;code&gt;rm&lt;/code&gt; command that accepts more user input other than the initial input to decide if you want to delete a file or folder or not; if the &lt;code&gt;else&lt;/code&gt;  block is executed (not from pipe) then it runs the command as normal.&lt;/p&gt;

&lt;p&gt;You should, of course, be careful with &lt;code&gt;rm&lt;/code&gt; and therefore I added the extra test logic to add extra security.&lt;/p&gt;

&lt;p&gt;This example is dependant on &lt;em&gt;Bash&lt;/em&gt; as the shell.&lt;/p&gt;

&lt;h5&gt;
  
  
  RM Program Function Wrapper
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;function &lt;/span&gt;rm_pipe &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;local &lt;/span&gt;input input_user
        &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; input&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
            if&lt;/span&gt;  &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
                &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Would you like to delete: %s: (y/[N])?\n'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                &lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; 1 input_user &lt;span class="c"&gt;# '-u 1' read from keyboard rather than stdin; defaults to No.&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input_user&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^&lt;span class="o"&gt;([&lt;/span&gt;yY]|[yY][eE][sS]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                    &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;# if user input is yes then process...&lt;/span&gt;
                &lt;span class="k"&gt;fi
            fi
        done
    else &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  RM Program Function Example
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;fake
 &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;
a
b
c
d
 &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; | rm_pipe &lt;span class="nt"&gt;-rf&lt;/span&gt;
Would you like to delete: a: &lt;span class="o"&gt;(&lt;/span&gt;y/[N]&lt;span class="o"&gt;)&lt;/span&gt;?
y 
Would you like to delete: b: &lt;span class="o"&gt;(&lt;/span&gt;y/[N]&lt;span class="o"&gt;)&lt;/span&gt;?

Would you like to delete: c: &lt;span class="o"&gt;(&lt;/span&gt;y/[N]&lt;span class="o"&gt;)&lt;/span&gt;?
no
Would you like to delete: d: &lt;span class="o"&gt;(&lt;/span&gt;y/[N]&lt;span class="o"&gt;)&lt;/span&gt;?
&lt;span class="nb"&gt;yes&lt;/span&gt;
 &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt;
b
c
 &lt;span class="err"&gt;$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This makes almost any builtin command, function, or executable file program accessible to pipe in the Linux command line. I make these types of functions for many things and they end up saving lots of time and effort so I don't always have to write extra array creating logic first and/or the function does my logic for me.&lt;/p&gt;

</description>
      <category>shell</category>
      <category>bash</category>
      <category>linux</category>
      <category>functions</category>
    </item>
    <item>
      <title>Turn any Bash function/alias into a hybrid executable/source-able script.</title>
      <dc:creator>Ian Pride</dc:creator>
      <pubDate>Wed, 03 Feb 2021 23:37:46 +0000</pubDate>
      <link>https://dev.to/thefluxapex/turn-any-bash-function-alias-into-a-hybrid-executable-source-able-script-53a3</link>
      <guid>https://dev.to/thefluxapex/turn-any-bash-function-alias-into-a-hybrid-executable-source-able-script-53a3</guid>
      <description>&lt;h1&gt;
  
  
  Convert any Bash Function/Alias to Hybrid Executable and Source-able Script with Bash Completion
&lt;/h1&gt;

&lt;p&gt;...works with arguments and stdin.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;br&gt;
I will be refactoring &lt;code&gt;cronstat&lt;/code&gt; (a function you'll find &lt;strong&gt;&lt;em&gt;below&lt;/em&gt;&lt;/strong&gt;) again to process the switches and arguments better. &lt;strong&gt;COMING VERY SOON&lt;/strong&gt;, just not sure when.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1.svg%3Flabel%3DSkill%2520Level%26message%3DIntermediate%26color%3Dffc40d%26style%3Dfor-the-badge%26labelColor%3D1d1d1d%26logo%3Dlinux" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1.svg%3Flabel%3DSkill%2520Level%26message%3DIntermediate%26color%3Dffc40d%26style%3Dfor-the-badge%26labelColor%3D1d1d1d%26logo%3Dlinux" alt="Skill Level"&gt;&lt;/a&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1.svg%3Flabel%3DBut%26message%3DBeginner%2520Friendly%26color%3D00a300%26style%3Dfor-the-badge%26labelColor%3D1d1d1d%26logo%3Dlinux" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimg.shields.io%2Fstatic%2Fv1.svg%3Flabel%3DBut%26message%3DBeginner%2520Friendly%26color%3D00a300%26style%3Dfor-the-badge%26labelColor%3D1d1d1d%26logo%3Dlinux" alt="Skill Level"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Motivation&lt;/li&gt;
&lt;li&gt;
How it works

&lt;ul&gt;
&lt;li&gt;Description&lt;/li&gt;
&lt;li&gt;
Generic Example

&lt;ul&gt;
&lt;li&gt;To Execute&lt;/li&gt;
&lt;li&gt;To Source With Completion&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Better Example

&lt;ul&gt;
&lt;li&gt;Example When Sourced&lt;/li&gt;
&lt;li&gt;Example When executed As Script&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Methods For Organization&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Whether you are new or old to scripting/programming in the Bash environment in Linux you have more than likely heard of, used, and/or created Bash functions and aliases. I will not be getting too much into what these are as this post states about the skill level that this is aimed at people who are familiar with these things. Having said that; I don't think that this will be too difficult for newer people to understand and, of course, all are welcome to read.&lt;/p&gt;
&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;There are a couple of ways to use functions and aliases; one is to source a file/script that contains the code and execute the function in the calling file and the other is to execute a script file with the code and pass arguments to the script and pass it to the function in the script.&lt;/p&gt;

&lt;p&gt;Over the years I have written countless functions and scripts and for a long time I would at first keep functions in my normal .bash_profile and just keep transferring it to different machines, but after a while my file started to grow too large and so I started putting them in separate &lt;em&gt;.bash_funcs&lt;/em&gt;/&lt;em&gt;.bash_aliases&lt;/em&gt; files and just sourced them in whatever main profile file I was using to try and stay organized.&lt;/p&gt;

&lt;p&gt;This method was fine, but I soon realized that functions and aliases can only be used in certain environments like scripts and command lines and not in things like &lt;em&gt;Alt+F2&lt;/em&gt;, &lt;em&gt;KDE Runner&lt;/em&gt;, &lt;em&gt;AutoKey&lt;/em&gt;, or just set to a &lt;em&gt;hotkey&lt;/em&gt; and so I realised I should just start putting functions in script files always so I can access them from anywhere and in any way.&lt;/p&gt;

&lt;p&gt;I soon created this method from my understanding of the Bash shell environment. I don't know if anyone else uses this method, but I have never seen it before and all due respect to those who do use something like this.&lt;/p&gt;
&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Description
&lt;/h3&gt;

&lt;p&gt;To call a function or alias from a script you must put said function (or alias) in a script and call script with any arguments you would pass to the function and in the same script underneath the function you would either put a bash &lt;em&gt;complete&lt;/em&gt; command if the file is sourced or execute the function with any arguments passed to the script.&lt;/p&gt;
&lt;h3&gt;
  
  
  Generic Example
&lt;/h3&gt;

&lt;p&gt;Generic, non-sense script example file &lt;code&gt;fake_function.bash&lt;/code&gt; (or whatever):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/usr/bin/env bash&lt;/span&gt;

&lt;span class="k"&gt;function &lt;/span&gt;fake_function &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-gt&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'Argument: %s\n'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;else return &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;# if file is sourced set Bash completion&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;complete&lt;/span&gt; &lt;span class="nt"&gt;-W&lt;/span&gt; &lt;span class="s2"&gt;"word1 word2 word3"&lt;/span&gt; fake_function
&lt;span class="k"&gt;else&lt;/span&gt; 
    &lt;span class="c"&gt;# else if file is executed pass arguments to it&lt;/span&gt;
    fake_function &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="c"&gt;# or || exit "$?" in some cases for errors&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  To Execute
&lt;/h4&gt;

&lt;p&gt;and then to execute the script with whatever method; for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;./fake_function.bash &lt;span class="s2"&gt;"Line 1"&lt;/span&gt; &lt;span class="s2"&gt;"Line 2"&lt;/span&gt;
Line 1
Line 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  To Source With Completion
&lt;/h4&gt;

&lt;p&gt;or to source into a script file with completion (&lt;code&gt;script_file&lt;/code&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;ff_path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"/path/to/fake_function.bash"&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ff_path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="c"&gt;# if the script exists&lt;/span&gt;
    &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ff_path&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="c"&gt;# source the file and function&lt;/span&gt;
&lt;span class="k"&gt;fi

&lt;/span&gt;fake_function &lt;span class="s2"&gt;"Line 1"&lt;/span&gt; &lt;span class="s2"&gt;"Line2"&lt;/span&gt; &lt;span class="c"&gt;# call the function&lt;/span&gt;
&lt;span class="c"&gt;# and call the function any time from the&lt;/span&gt;
&lt;span class="c"&gt;# command line&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Better Example
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;*NOTE*: This has been refactored to remove redundancy.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is an actual example of a function and script I wrote called &lt;code&gt;cronstat&lt;/code&gt; (&lt;code&gt;cronstat.bash&lt;/code&gt;) that is a wrapper for the &lt;em&gt;&lt;code&gt;stat&lt;/code&gt;&lt;/em&gt; command that filters out the newest (default) or oldest files, directory, or both (default) in a directory. Great for when I need to find the latest project I did  and forgot the name of or finding old, redundant files etc...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/usr/bin/env bash&lt;/span&gt;

&lt;span class="k"&gt;function &lt;/span&gt;cronstat &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;&lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1 &lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 arg
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-gt&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        for &lt;/span&gt;arg &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;hH]|-[hH][eE][lL][pP]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="no"&gt;EOF&lt;/span&gt;&lt;span class="sh"&gt;

 'cronstat' - 'stat' wrapper to find the oldest
 and newest file, directory, or both from an
 arrayed or line delimited list.

 @USAGE:
    cronstat &amp;lt;LIST&amp;gt; [OPTIONS...]
    &amp;lt;LIST&amp;gt; | cronstat [OPTIONS...]

 @LIST:
    Any arrayed list of files or directories
    or the output of the 'find' or 'ls'
    commands etc...

 @OPTIONS:
    -h,--help       This help screen.
    -b,--bare       Print the path only, no
                    extra information.
    -f,--file       Filter by files.
    -d,--directory  Filter by directories.
                    Defaults to any file or
                    directory.
    -o,--oldest     Get the oldest item.
                    Defaults to the newest.
 @EXAMPLES:
    cronstat &lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="sh"&gt;(find -maxdepth 1)
    find -maxdepth 1 | cronstat
    IFS=&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="sh"&gt;(echo -en "&lt;/span&gt;&lt;span class="se"&gt;\n\b&lt;/span&gt;&lt;span class="sh"&gt;") array=(&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="sh"&gt;(ls -A --color=auto))
    cronstat &lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="sh"&gt;{array[@]} --file
    printf '%s&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sh"&gt;' "&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="sh"&gt;{array[@]}" | cronstat -odb

 @EXITCODES:
    0               No errors.
    1               No array or list passed.
    2               No values in list.
&lt;/span&gt;&lt;span class="no"&gt;
EOF
&lt;/span&gt;                &lt;span class="k"&gt;return
            fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;bB]|-[bB][aA][rR][eE]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;fF]|-[fF][iI][lL][eE]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;dD]|-[dD][iI][rR][eE][cC][tT][oO][rR][yY]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;oO]|-[oO][lL][dD][eE][sS][tT]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;oO][fF]|[fF][oO]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;oO][dD]|[dD][oO]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;oO][bB]|[bB][oO]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
                &lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi

            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;fF][bB]|[bB][fF]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
                &lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;dD][bB]|[bB][dD]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
                &lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi

            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;oO][fF][bB]|[oO][bB][fF]|&lt;span class="se"&gt;\&lt;/span&gt;
                            &lt;span class="o"&gt;[&lt;/span&gt;bB][oO][fF]|[bB][fF][oO]|&lt;span class="se"&gt;\&lt;/span&gt;
                            &lt;span class="o"&gt;[&lt;/span&gt;fF][oO][bB]|[fF][bB][oO]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
                &lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
            if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$arg&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;~ ^-&lt;span class="o"&gt;([&lt;/span&gt;oO][dD][bB]|[oO][bB][dD]|&lt;span class="se"&gt;\&lt;/span&gt;
                            &lt;span class="o"&gt;[&lt;/span&gt;bB][oO][dD]|[bB][dD][oO]|&lt;span class="se"&gt;\&lt;/span&gt;
                            &lt;span class="o"&gt;[&lt;/span&gt;dD][oO][bB]|[dD][bB][oO]&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nv"&gt;bare_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
                &lt;span class="nv"&gt;time_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;2
                &lt;span class="nv"&gt;path_mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3
                &lt;span class="nb"&gt;shift
            &lt;/span&gt;&lt;span class="k"&gt;fi
        done
    fi
    &lt;/span&gt;&lt;span class="nb"&gt;local &lt;/span&gt;input array &lt;span class="nb"&gt;date &lt;/span&gt;iter &lt;span class="nv"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 value &lt;span class="nv"&gt;time_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Newest"&lt;/span&gt; &lt;span class="nv"&gt;path_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"File Or Directory"&lt;/span&gt;
    &lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; array
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-t&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        while &lt;/span&gt;&lt;span class="nb"&gt;read&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; input&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
            case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path_mode&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
                &lt;/span&gt;1&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt;  &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
                        &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                        &lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %Z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
                        array[&lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                    &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
                2&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                        &lt;/span&gt;&lt;span class="nv"&gt;path_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"File"&lt;/span&gt;
                        &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %Z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
                        array[&lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                    &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
                3&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                        &lt;/span&gt;&lt;span class="nv"&gt;path_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Directory"&lt;/span&gt;
                        &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %Z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
                        array[&lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                    &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
            &lt;span class="k"&gt;esac&lt;/span&gt;
        &lt;span class="k"&gt;done
    else
        if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$# &lt;/span&gt;&lt;span class="nt"&gt;-gt&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
            for &lt;/span&gt;input &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
                case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path_mode&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
                    &lt;/span&gt;1&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt;  &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt;
                            &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                            &lt;/span&gt;&lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %Z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
                            array[&lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                        &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
                    2&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                            &lt;/span&gt;&lt;span class="nv"&gt;path_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"File"&lt;/span&gt;
                            &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %Z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
                            array[&lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                        &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
                    3&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                            &lt;/span&gt;&lt;span class="nv"&gt;path_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Directory"&lt;/span&gt;
                            &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %Z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
                            array[&lt;span class="nv"&gt;$date&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$input&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                        &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
                &lt;span class="k"&gt;esac&lt;/span&gt;
            &lt;span class="k"&gt;done
        else return &lt;/span&gt;1&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;fi
    fi
    if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="k"&gt;${#&lt;/span&gt;&lt;span class="nv"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
         return &lt;/span&gt;2
    &lt;span class="k"&gt;fi
    for &lt;/span&gt;iter &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="p"&gt;!array[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
        if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$index&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
            &lt;/span&gt;&lt;span class="nv"&gt;index&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$((&lt;/span&gt;index &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="k"&gt;))&lt;/span&gt;
            &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$iter&lt;/span&gt;
        &lt;span class="k"&gt;fi
        case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$time_mode&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
            &lt;/span&gt;1&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$iter&lt;/span&gt; &lt;span class="nt"&gt;-gt&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                    &lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$iter&lt;/span&gt;
                &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
            2&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$iter&lt;/span&gt; &lt;span class="nt"&gt;-lt&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                    &lt;/span&gt;&lt;span class="nv"&gt;time_string&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Oldest"&lt;/span&gt;
                    &lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$iter&lt;/span&gt;
                &lt;span class="k"&gt;fi&lt;/span&gt;&lt;span class="p"&gt;;;&lt;/span&gt;
        &lt;span class="k"&gt;esac&lt;/span&gt;
    &lt;span class="k"&gt;done
    &lt;/span&gt;&lt;span class="nv"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nv"&gt;$bare_mode&lt;/span&gt; &lt;span class="nt"&gt;-eq&lt;/span&gt; 0 &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
        &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'\n%s %s:\n%s\n\nLast Changed:\n%s\n\n'&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$time_string&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$path_string&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
            &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;stat&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; %z &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;else
        &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&amp;gt;&amp;amp;1&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
    &lt;/span&gt;&lt;span class="nb"&gt;complete&lt;/span&gt; &lt;span class="nt"&gt;-W&lt;/span&gt; &lt;span class="s2"&gt;"-h --help -o --oldest -f --file -d --directory -b --bare -of -od -ob -fb -db -ofb -odb '&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;(find -maxdepth 1)'"&lt;/span&gt; cronstat
&lt;span class="k"&gt;else &lt;/span&gt;cronstat &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;fi&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and just like the generic example above you would then either execute this file with any arguments or source it into your dot or script files and use however tied to any program or hotkey as mentioned before and these examples here:&lt;/p&gt;

&lt;h4&gt;
  
  
  Example When Sourced
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'%s\n'&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; .&lt;span class="k"&gt;*&lt;/span&gt; | cronstat &lt;span class="nt"&gt;--oldest&lt;/span&gt;

Oldest File Or Directory:
examples.desktop

Last Changed:
2020-03-21 11:43:36.356069642 &lt;span class="nt"&gt;-0500&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Example When executed As Script
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; &lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; &lt;span class="nt"&gt;--color&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;auto | ~/.bash/profile/functions/cronstat.bash &lt;span class="nt"&gt;--oldest&lt;/span&gt; &lt;span class="nt"&gt;--directory&lt;/span&gt;

Oldest Directory:
.pki

Last Changed:
2020-03-23 08:09:05.447080464 &lt;span class="nt"&gt;-0500&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Methods For Organization
&lt;/h2&gt;

&lt;p&gt;A main issue with script files is that you can end up with a lot of them and it's horrible if you don't keep them organized and I end up dropping all of my &lt;em&gt;function&lt;/em&gt; (&lt;em&gt;.bash&lt;/em&gt;) files into a &lt;em&gt;functions&lt;/em&gt; folder and &lt;em&gt;aliases&lt;/em&gt; and then in either a dot profile or func file I will try and import them all like this:&lt;/p&gt;

&lt;p&gt;(in &lt;em&gt;.bash_funcs&lt;/em&gt; or &lt;em&gt;.bash_profile&lt;/em&gt; etc...)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;*NOTE*: This has been refactored to work with file names with '-'.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Load funcs&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;bash_func_src &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;file
    &lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;find &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/.bash/profile/functions/"&lt;/span&gt; &lt;span class="nt"&gt;-maxdepth&lt;/span&gt; 1 &lt;span class="nt"&gt;-type&lt;/span&gt; f &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.bash"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
bash_func_src

&lt;span class="c"&gt;# and aliases&lt;/span&gt;
&lt;span class="k"&gt;function &lt;/span&gt;bash_alias_src &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;local &lt;/span&gt;file
    &lt;span class="k"&gt;for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;find &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;HOME&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/.bash/profile/aliases/"&lt;/span&gt; &lt;span class="nt"&gt;-maxdepth&lt;/span&gt; 1 &lt;span class="nt"&gt;-type&lt;/span&gt; f &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.bash"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
bash_alias_src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This method essentially makes any of your Bash code portable and accessible in all sorts of environments and allows you keep it in a script, transporting not only your code, but also examples of usage (in terms of the script itself) and a place to store external Bash completion code all the while archiving everything.&lt;/p&gt;

&lt;p&gt;This allows you to execute these functions from a script for use anywhere especially in hotkeys (&lt;em&gt;AutoKey&lt;/em&gt;), &lt;em&gt;Alt+F2&lt;/em&gt;, &lt;em&gt;KDE Runner&lt;/em&gt;, and any other way you can call a script with arguments. &lt;/p&gt;

&lt;p&gt;I hope this helps someone and I'd love to hear if you do something similar or just any tips or comments are welcome.&lt;/p&gt;

</description>
      <category>bash</category>
      <category>tips</category>
      <category>intermediate</category>
      <category>function</category>
    </item>
    <item>
      <title>Advice for building a cross-platform RUST gui</title>
      <dc:creator>Ian Pride</dc:creator>
      <pubDate>Tue, 10 Nov 2020 21:37:00 +0000</pubDate>
      <link>https://dev.to/thefluxapex/advice-for-building-a-cross-platform-rust-gui-34m7</link>
      <guid>https://dev.to/thefluxapex/advice-for-building-a-cross-platform-rust-gui-34m7</guid>
      <description>&lt;p&gt;&lt;code&gt;TDLR&lt;/code&gt;; - What &lt;strong&gt;Rust&lt;/strong&gt; desktop gui crate/framework do you use or recommend for use in &lt;em&gt;Windows&lt;/em&gt; and &lt;em&gt;Linux&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;Need some advice on what some of you &lt;em&gt;Rustaceans&lt;/em&gt; prefer to use to build desktop guis; especially cross-platform for &lt;em&gt;Windows&lt;/em&gt; and &lt;em&gt;Linux&lt;/em&gt;. I'll build it for &lt;em&gt;Mac&lt;/em&gt; if there isn't much extra effort involved.&lt;/p&gt;

&lt;p&gt;I've done my own research, but I'm just asking the community for your preferences/experiences. It's looking like &lt;code&gt;Druid&lt;/code&gt; will be my first try unless I get some better advice, although I'll eventually try everything.&lt;/p&gt;

&lt;p&gt;I recently re-wrote the CLI version of one of my programs (3rd iteration; 1st was &lt;em&gt;AutoHotkey&lt;/em&gt; in Windows and 2nd is cross-platform in &lt;em&gt;Python&lt;/em&gt;) in &lt;em&gt;Rust&lt;/em&gt; and now I'd like to build the gui version for it. Not really much to the gui except for 2 &lt;em&gt;i32&lt;/em&gt; inputs, displayed text, and possible a &lt;em&gt;copy to clipboard&lt;/em&gt; feature. &lt;/p&gt;

</description>
      <category>help</category>
      <category>rust</category>
    </item>
    <item>
      <title>AutoHotkey Beginner Tip #2: SetBatchLines - Script Performance</title>
      <dc:creator>Ian Pride</dc:creator>
      <pubDate>Sun, 24 May 2020 00:05:15 +0000</pubDate>
      <link>https://dev.to/thefluxapex/autohotkey-setbatchlines-script-performance-3l24</link>
      <guid>https://dev.to/thefluxapex/autohotkey-setbatchlines-script-performance-3l24</guid>
      <description>&lt;h1&gt;
  
  
  Programming/Scripting/Coding Language Performance
&lt;/h1&gt;

&lt;p&gt;I won't be getting deep into the performance of programming languages (as that would draw debates I'm not ready to get into 😁), but if you are familiar with the subject then you probably understand that higher level languages (unless compiled sometimes) can be slower in some areas of computing compared to lower level languages like the C family and Assembly (among others) etc; though this doesn't always matter much anymore as CPU's got faster and RAM got bigger. This, of course, is not true for stuff you want to be doing at, say, NASA 😁.&lt;/p&gt;

&lt;h1&gt;
  
  
  AutoHotkey - Performance
&lt;/h1&gt;

&lt;p&gt;AutoHotkey is by far my favorite language to code in Windows for various reasons for most everyday tasks from simple routine automation to full-on interactive programs with GUIs and in my opinion it compares to other languages of its kind when it comes to speed; if you know how to use the language well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Using SetBatchLines
&lt;/h2&gt;

&lt;p&gt;There are a few ways to optimize performance in AutoHotkey for window interaction, key detection/execution, and what I am speaking about here: script execution. Mostly pertaining to loops and timers.&lt;/p&gt;

&lt;p&gt;One method to improve script performance is by using the 'SetBatchLines' command.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use SetBatchLines Command
&lt;/h3&gt;

&lt;p&gt;By default AutoHotkey executes lines for 10ms and then sleeps for 10ms and this is great for misc default profile scripts or simple automation tasks, but when doing things more intensive (such as looping though indexed or associative arrays to execute/increment code/data) this can slow down the script (or timer/function) quite a bit with large indexed arrays.&lt;/p&gt;

&lt;p&gt;Excerpt from AutoHotkey Docs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Determines how fast a script will run (affects CPU utilization).&lt;br&gt;
SetBatchLines, 20ms&lt;br&gt;
SetBatchLines, LineCount&lt;/p&gt;

&lt;p&gt;Parameters&lt;/p&gt;

&lt;p&gt;20ms&lt;br&gt;
(The 20ms is just an example.) If the value ends in ms, it indicates how often the script should sleep (each sleep is 10 ms long). In the following example, the script will sleep for 10ms every time it has run for 20ms: SetBatchLines, 20ms.&lt;/p&gt;

&lt;p&gt;LineCount&lt;br&gt;
The number of script lines to execute prior to sleeping for 10ms. The value can be as high as 9223372036854775807. Also, this mode is mutually exclusive of the 20ms mode in the previous paragraph; that is, only one of them can be in effect at a time.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SetBatchLines,-1
; [-1] Or the number of (# of iterations+exec lines)
; in a loop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is EXTREMELY important for performance when doing any kind of looping or SetTimers (maybe multithreading with DLL?) etc...&lt;/p&gt;

&lt;p&gt;You can either run the whole program with no sleep in its execution by placing the command at the top of a script or you can turn it on and off inside the loop for iteration precision control e.g.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;;; Initialize vars
maxRange:=100000
array := range(1,maxRange) ;; my range function
tmpIntVar:=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set each iteration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;;; Set and reset each iteration
for index, item in array
{
    SetBatchLines,-1 ;; set befeore execution
    ; or SetBatchLines,% (maxRange+3)
    tmpIntVar++ ;; do something
    SetBatchLines,10ms ;; default value
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or wrap the outside of the loop for smoothness:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SetBatchLines,-1
loop, % array.MaxIndex()
{
    tmpIntVar++
}
 SetBatchLines,10ms
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;The 'SetBatchLines' command is essential for controlling the flow and speed of a script and I believe a scource of confusion when it comes to why some people may think the language is slow or inefficient. With proper use of this command a program written in the language can be smooth.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>AutoHotkey Beginner Tip #1: Assignment Vs Expression Operator Usage</title>
      <dc:creator>Ian Pride</dc:creator>
      <pubDate>Wed, 27 Nov 2019 00:50:13 +0000</pubDate>
      <link>https://dev.to/thefluxapex/autohotkey-beginner-tip-1-assignment-vs-expression-operator-usage-10pg</link>
      <guid>https://dev.to/thefluxapex/autohotkey-beginner-tip-1-assignment-vs-expression-operator-usage-10pg</guid>
      <description>&lt;p&gt;Over the years I have helped many people with learning/debugging AutoHotkey in forums and one of the most common areas where people have issues (confusion) while learning AutoHotkey is with the difference between the assignment &amp;amp; expression operators '=' &amp;amp; ":=" respectively. Both can assign value, but the former is purely assignment; the latter is used for any expression (code to be executed/evaluated).&lt;/p&gt;

&lt;h2&gt;
  
  
  Assigning value with the assignment '=' operator
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;varName = Any unquoted string.&lt;/li&gt;
&lt;li&gt;varName = %anotherVarName%&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Assigning value with the expression ":=" operator
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;varName := "Any quoted string."&lt;/li&gt;
&lt;li&gt;varName := anotherVarName&lt;/li&gt;
&lt;li&gt;varName := !anotherVarName?0:255&lt;/li&gt;
&lt;li&gt;varName := !anotherVarName?"Yes":"No"&lt;/li&gt;
&lt;li&gt;varName := ((anotherVarName == "whatImTestingFor")?"Value exists":"Value doesn't exist")&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Differences
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;=&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Doesn't use quotation marks for strings.&lt;/li&gt;
&lt;li&gt;Variable names must be wrapped with %%.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;:=&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Needs quotation marks for strings.&lt;/li&gt;
&lt;li&gt;Variable names don't need to be wrapped.&lt;/li&gt;
&lt;li&gt;Can contain any possible expression operation in the language.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Opinion
&lt;/h2&gt;

&lt;p&gt;In my opinion there's only one use for '=' ever. :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;'=' can be used to strip leading and trailing spaces from variables&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;E.g. varName := " String with spaces "&lt;/li&gt;
&lt;li&gt;     varName = %varName%&lt;/li&gt;
&lt;li&gt;     Result: varName == "String with spaces"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything else can always be done with ':='. That, of course, is your preference.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Disclaimer
&lt;/h3&gt;

&lt;p&gt;This is my first post here &amp;amp; I'm very aware of the hate for AHK by many so I will write my disclaimer here once.&lt;/p&gt;

&lt;p&gt;Even though I know quite a few other languages I will always be an AutoHotkey advocate.&lt;/p&gt;

&lt;p&gt;Many people do not like the chaotic syntax of AHK, but once you understand it &amp;amp; create your own consistent style it's actually quite nice (IMO?). I am aware of it's inadequecies in certain areas, but like many other languages it is still useful for many things (We can even plug in to UWP with Selenium now :D).&lt;/p&gt;

</description>
      <category>autohotkey</category>
      <category>beginners</category>
      <category>tips</category>
      <category>expressions</category>
    </item>
  </channel>
</rss>
