Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to make a generic Bash function that can accept information via positional and named arguments
    primarykey
    data
    text
    <p>I'm writing a large number of Bash functions that are to be capable of acquiring different pieces of information from the command line passed using positional arguments <em>or</em> named arguments (provided by <code>getopts</code>). The idea is that positional arguments are to be used largely for briskness and direct human control while named arguments are to be used largely for clarity and control by other functions. To illustrate how I am thinking about this, consider a function that can convert from one thing to another. This function can be used, broadly speaking, in a quick mode or in an advanced mode. In the quick mode, few arguments are specified and, generally, are positional arguments, while in the advanced mode, many arguments can be specified and, generally, are named arguments. For examples...</p> <h1>quick mode</h1> <p>This mode can be used in a manner such as the following:</p> <pre><code>function fileName1 fileName2 </code></pre> <p>It converts one file to another using internal assumptions and measurements made autonomously.</p> <h1>advanced mode</h1> <p>This mode can be used in a manner such as the following:</p> <pre><code>function -i fileName1 -o fileName2 -m -r 100 -v </code></pre> <p>This mode can be used also in a manner such as the following:</p> <pre><code>function -m -v fileName1 fileName2 -r 100 </code></pre> <p>Note that <code>-v</code> accepts no argument. It is an option only (specifying something such as verbosity).</p> <hr> <p>So, the logic in this case would be that the first <em>positional</em> argument is assumed to be <code>fileName1</code> and the second positional argument is assumed to be <code>fileName2</code> <em>unless</em> either of these file names are specified using the <code>-i</code> or <code>-o</code> options, in which case <em>they</em> are used because they are given higher priority (and the first and second positional arguments are ignored).</p> <p>I ask for suggestions and guidance in implementing these types of requirements in <em>as general a way as possible</em> because this approach is to be applied to a library of over 150 functions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload