Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A few tidbits that should help: when you call a function with a string, the string is split into multiple arguments (the <a href="http://www.gnu.org/software/bash/manual/html_node/Positional-Parameters.html#Positional-Parameters" rel="noreferrer">positional parameters</a>, named <code>$<i>n</i></code>, where <i>n</i> are integers starting at 1) on the characters in the variable <a href="http://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html#Word-Splitting" rel="noreferrer"><code>$IFS</code></a> (which defaults to spaces, tabs and newlines)</p> <pre><code>function first() { echo $1 } first one two three # outputs: "one" </code></pre> <p><a href="http://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html#Special-Parameters" rel="noreferrer"><code>$*</code> and <code>$@</code></a> give you all the positional parameters, in order.</p> <p>Second, the special variable <a href="http://www.gnu.org/software/bash/manual/html_node/Special-Parameters.html#index-g_t_0023-73" rel="noreferrer"><code>$#</code></a> holds the number of arguments to a function.</p> <p>Third, <a href="http://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html#index-shift-121" rel="noreferrer"><code>shift</code></a> discards the first positional parameter and moves up all the others by one.</p> <pre><code>function tail() { shift echo $* } </code></pre> <p>Fourth, you can capture the output of commands and functions using <a href="http://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html#Command-Substitution" rel="noreferrer">`...` or <code>$(...)</code></a></p> <pre><code>rest=`tail $*` </code></pre> <p>Fifth, you can send the output of one command to the input of another using the <a href="http://www.gnu.org/software/bash/manual/html_node/Pipelines.html#Pipelines" rel="noreferrer">pipe character</a> (<code>|</code>):</p> <pre><code>seq 5 | sort </code></pre>
 

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