Heray-Was-Here
Server : Apache
System : Linux vps43555.mylogin.co 3.10.0-1160.53.1.vz7.185.3 #1 SMP Tue Jan 25 12:49:12 MSK 2022 x86_64
User : redsea ( 60651)
PHP Version : 7.4.32
Disable Function : NONE
Directory :  /usr/share/doc/fish/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/doc/fish/commands.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="generator" content="Doxygen 1.8.8"/>
<title>fish: Commands</title>
<link href="user_doc.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top" class="qindex"><!-- do not close this div here, it is closed by doxygen! -->
<a href="http://fishshell.com/"><code>fish</code> shell</a>
|
<a href="index.html">Documentation</a>
|
<a href="tutorial.html">Tutorial</a>
|
<a href="design.html">Design</a>
|
<a href="commands.html">Commands</a>
|
<a href="faq.html">FAQ</a>
|
<a href="license.html">License</a>
<!-- Generated by Doxygen 1.8.8 -->
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Commands </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock">
<div class="fish_left_bar">
<div class="logo"></div>
<div class="menu commands_menu">
<ul>
<li><a href="#abbr">abbr</a></li>
<li><a href="#alias">alias</a></li>
<li><a href="#and">and</a></li>
<li><a href="#begin">begin</a></li>
<li><a href="#bg">bg</a></li>
<li><a href="#bind">bind</a></li>
<li><a href="#block">block</a></li>
<li><a href="#breakpoint">breakpoint</a></li>
<li><a href="#break">break</a></li>
<li><a href="#builtin">builtin</a></li>
<li><a href="#case">case</a></li>
<li><a href="#cd">cd</a></li>
<li><a href="#commandline">commandline</a></li>
<li><a href="#command">command</a></li>
<li><a href="#complete">complete</a></li>
<li><a href="#contains">contains</a></li>
<li><a href="#continue">continue</a></li>
<li><a href="#count">count</a></li>
<li><a href="#dirh">dirh</a></li>
<li><a href="#dirs">dirs</a></li>
<li><a href="#echo">echo</a></li>
<li><a href="#else">else</a></li>
<li><a href="#emit">emit</a></li>
<li><a href="#end">end</a></li>
<li><a href="#eval">eval</a></li>
<li><a href="#exec">exec</a></li>
<li><a href="#exit">exit</a></li>
<li><a href="#false">false</a></li>
<li><a href="#fg">fg</a></li>
<li><a href="#fish_config">fish_config</a></li>
<li><a href="#fish_indent">fish_indent</a></li>
<li><a href="#fish_key_reader">fish_key_reader</a></li>
<li><a href="#fish_prompt">fish_prompt</a></li>
<li><a href="#fish_realpath">fish_realpath</a></li>
<li><a href="#fish_right_prompt">fish_right_prompt</a></li>
<li><a href="#fish">fish</a></li>
<li><a href="#fish_update_completions">fish_update_completions</a></li>
<li><a href="#fish_vi_mode">fish_vi_mode</a></li>
<li><a href="#for">for</a></li>
<li><a href="#funced">funced</a></li>
<li><a href="#funcsave">funcsave</a></li>
<li><a href="#functions">functions</a></li>
<li><a href="#function">function</a></li>
<li><a href="#help">help</a></li>
<li><a href="#history">history</a></li>
<li><a href="#if">if</a></li>
<li><a href="#isatty">isatty</a></li>
<li><a href="#jobs">jobs</a></li>
<li><a href="#math">math</a></li>
<li><a href="#nextd">nextd</a></li>
<li><a href="#not">not</a></li>
<li><a href="#open">open</a></li>
<li><a href="#or">or</a></li>
<li><a href="#popd">popd</a></li>
<li><a href="#prevd">prevd</a></li>
<li><a href="#printf">printf</a></li>
<li><a href="#prompt_pwd">prompt_pwd</a></li>
<li><a href="#psub">psub</a></li>
<li><a href="#pushd">pushd</a></li>
<li><a href="#pwd">pwd</a></li>
<li><a href="#random">random</a></li>
<li><a href="#read">read</a></li>
<li><a href="#return">return</a></li>
<li><a href="#set_color">set_color</a></li>
<li><a href="#set">set</a></li>
<li><a href="#source">source</a></li>
<li><a href="#status">status</a></li>
<li><a href="#string">string</a></li>
<li><a href="#suspend">suspend</a></li>
<li><a href="#switch">switch</a></li>
<li><a href="#test">test</a></li>
<li><a href="#trap">trap</a></li>
<li><a href="#true">true</a></li>
<li><a href="#type">type</a></li>
<li><a href="#ulimit">ulimit</a></li>
<li><a href="#umask">umask</a></li>
<li><a href="#vared">vared</a></li>
<li><a href="#while">while</a></li>
</ul>

</div>
</div>
<div class="commands fish_right_bar">
<h1 class="interior_title">Command reference</h1>
<p> <code>fish</code> ships with a large number of builtin commands, shellscript functions and external commands. These are all described below.</p>
<p>Almost all fish commands respond to the <code>-h</code> or <code>--help</code> options to display their relevant help, also accessible using the <code>help</code> and <code>man</code> commands, like so:</p>
 
 <pre class="fish">
<span class="command">echo</span> <span class="argument">-h</span>
<span class="command">echo</span> <span class="argument">--help</span>
<span class="comment"># Prints help to the terminal window</span>

<span class="binary">man</span> <span class="argument">echo</span>
<span class="comment"># Displays the man page in the system pager</span>
<span class="comment"># (normally 'less', 'more' or 'most').</span>

<span class="command">help</span> <span class="argument">echo</span>
<span class="comment"># Open a web browser to show the relevant documentation</span>
</pre><hr/>
 <h1><a class="anchor" id="abbr"></a>
abbr - manage fish abbreviations</h1>
<h2><a class="anchor" id="abbr-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">abbr</span> <span class="argument">-a</span> <span class="argument">word</span> <span class="argument">phrase...</span>
<span class="command">abbr</span> <span class="argument">-s</span>
<span class="command">abbr</span> <span class="argument">-l</span>
<span class="command">abbr</span> <span class="argument">-e</span> <span class="argument">word</span>
</pre><h2><a class="anchor" id="abbr-description"></a>
Description</h2>
<p><code>abbr</code> manipulates the list of abbreviations that fish will expand.</p>
<p>Abbreviations are user-defined character sequences or words that are replaced with longer phrases after they are entered. For example, a frequently-run command such as <code>git checkout</code> can be abbreviated to <code>gco</code>. After entering <code>gco</code> and pressing <span class="key"><b>Space</b></span> or <span class="key"><b>Enter</b></span>, the full text <code>git checkout</code> will appear in the command line.</p>
<p>Abbreviations are stored using universal variables. You can create abbreviations directly on the command line, and they will be saved automatically. Calling <code>abbr -a</code> in config.fish will lead to slightly worse startup performance.</p>
<p>The following parameters are available:</p>
<ul>
<li><code>-a WORD PHRASE</code> or <code>--add WORD PHRASE</code> Adds a new abbreviation, where WORD will be expanded to PHRASE.</li>
<li><code>-s</code> or <code>--show</code> Show all abbreviated words and their expanded phrases in a manner suitable for export and import.</li>
<li><code>-l</code> or <code>--list</code> Lists all abbreviated words.</li>
<li><code>-e WORD</code> or <code>--erase WORD</code> Erase the abbreviation WORD.</li>
</ul>
<p>Note: fish version 2.1 supported <code>-a WORD=PHRASE</code>. This syntax is now deprecated but will still be converted.</p>
<h2><a class="anchor" id="abbr-example"></a>
Examples</h2>
 
 <pre class="fish">
<span class="command">abbr</span> <span class="argument">-a</span> <span class="argument">gco</span> <span class="argument">git</span> <span class="argument">checkout</span>
</pre><p>Add a new abbreviation where <code>gco</code> will be replaced with <code>git checkout</code>.</p>
 
 <pre class="fish">
<span class="command">abbr</span> <span class="argument">-e</span> <span class="argument">gco</span>
</pre><p>Erase the <code>gco</code> abbreviation.</p>
 
 <pre class="fish">
<span class="binary">ssh</span> <span class="argument">another_host</span> <span class="argument">abbr</span> <span class="argument">-s</span> <span class="redirect">|</span> <span class="command">source</span>
</pre><p>Import the abbreviations defined on another_host over SSH.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="alias"></a>
alias - create a function</h1>
<h2><a class="anchor" id="alias-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">alias</span> <span class="argument">NAME</span> <span class="argument">DEFINITION</span>
<span class="command">alias</span> <span class="argument">NAME=DEFINITION</span>
</pre><h2><a class="anchor" id="alias-description"></a>
Description</h2>
<p><code>alias</code> is a simple wrapper for the <code>function</code> builtin. It exists for backwards compatibility with Posix shells. For other uses, it is recommended to define a <a href="#function">function</a>.</p>
<p><code>fish</code> does not keep track of which functions have been defined using <code>alias</code>. They must be erased using <code>functions -e</code>.</p>
<ul>
<li><code>NAME</code> is the name of the alias</li>
<li><code>DEFINITION</code> is the actual command to execute. The string <code>$argv</code> will be appended.</li>
</ul>
<p>You cannot create an alias to a function with the same name.</p>
<p>Note that spaces need to be escaped in the call to alias just like in the commandline <em>even inside the quotes</em>.</p>
<h2><a class="anchor" id="alias-example"></a>
Example</h2>
<p>The following code will create <code>rmi</code>, which runs <code>rm</code> with additional arguments on every invocation.</p>
 
 <pre class="fish">
<span class="command">alias</span> <span class="argument">rmi</span> <span class="string">"rm -i"</span>

<span class="comment"># This is equivalent to entering the following function:</span>

<span class="command">function</span> <span class="argument">rmi</span>
    <span class="binary">rm</span> <span class="argument">-i</span> <span class="variable"><span class="operator">$</span>argv</span>
<span class="command">end</span>

<span class="comment"># This needs to have the spaces escaped or "Chrome.app..." will be seen as an argument to "/Applications/Google":</span>

<span class="command">alias</span> <span class="argument">chrome=</span><span class="string">'/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome banana'</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="and"></a>
and - conditionally execute a command</h1>
<h2><a class="anchor" id="and-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="argument">COMMAND1</span><span class="redirect">;</span> <span class="command">and</span> <span class="argument">COMMAND2</span>
</pre><h2><a class="anchor" id="and-description"></a>
Description</h2>
<p><code>and</code> is used to execute a command if the current exit status (as set by the previous command) is 0.</p>
<p><code>and</code> statements may be used as part of the condition in an <a href="#if"><code>and</code></a> or <a href="#while"><code>while</code></a> block. See the documentation for <a href="#if"><code>if</code></a> and <a href="#while"><code>while</code></a> for examples.</p>
<p><code>and</code> does not change the current exit status. The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.</p>
<h2><a class="anchor" id="and-example"></a>
Example</h2>
<p>The following code runs the <code>make</code> command to build a program. If the build succeeds, <code>make</code>'s exit status is 0, and the program is installed. If either step fails, the exit status is 1, and <code>make clean</code> is run, which removes the files created by the build process.</p>
 
 <pre class="fish">
<span class="binary">make</span><span class="redirect">;</span> <span class="command">and</span> <span class="binary">make</span> <span class="argument">install</span><span class="redirect">;</span> <span class="command">or</span> <span class="binary">make</span> <span class="argument">clean</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="begin"></a>
begin - start a new block of code</h1>
<h2><a class="anchor" id="begin-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">begin</span><span class="redirect">;</span> <span class="argument">[COMMANDS...;]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="begin-description"></a>
Description</h2>
<p><code>begin</code> is used to create a new block of code.</p>
<p>The block is unconditionally executed. <code>begin; ...; end</code> is equivalent to <code>if true; ...; end</code>.</p>
<p><code>begin</code> is used to group a number of commands into a block. This allows the introduction of a new variable scope, redirection of the input or output of a set of commands as a group, or to specify precedence when using the conditional commands like <code>and</code>.</p>
<p><code>begin</code> does not change the current exit status.</p>
<h2><a class="anchor" id="begin-example"></a>
Example</h2>
<p>The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends.</p>
 
 <pre class="fish">
<span class="command">begin</span>
    <span class="command">set</span> <span class="argument">-l</span> <span class="argument">PIRATE</span> <span class="argument">Yarrr</span>
    <span class="argument">...</span>
<span class="command">end</span>

<span class="command">echo</span> <span class="variable"><span class="operator">$</span>PIRATE</span>
<span class="comment"># This will not output anything, since the PIRATE variable</span>
<span class="comment"># went out of scope at the end of the block</span>
</pre><p>In the following code, all output is redirected to the file out.html.</p>
 
 <pre class="fish">
<span class="command">begin</span>
    <span class="command">echo</span> <span class="variable"><span class="operator">$</span>xml_header</span>
    <span class="command">echo</span> <span class="variable"><span class="operator">$</span>html_header</span>
    <span class="command">if</span> <span class="command">test</span> <span class="argument">-e</span> <span class="variable"><span class="operator">$</span>file</span>
        <span class="argument">...</span>
    <span class="command">end</span>
    <span class="argument">...</span>
<span class="command">end</span> <span class="redirect">&gt; out.html</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="bg"></a>
bg - send jobs to background</h1>
<h2><a class="anchor" id="bg-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">bg</span> <span class="argument">[PID...]</span>
</pre><h2><a class="anchor" id="bg-description"></a>
Description</h2>
<p><code>bg</code> sends <a href="index.html#syntax-job-control">jobs</a> to the background, resuming them if they are stopped. A background job is executed simultaneously with fish, and does not have access to the keyboard. If no job is specified, the last job to be used is put in the background. If PID is specified, the jobs with the specified process group IDs are put in the background.</p>
<p>The PID of the desired process is usually found by using <a href="index.html#expand-process">process expansion</a>.</p>
<h2><a class="anchor" id="bg-example"></a>
Example</h2>
<p><code>bg %1</code> will put the job with job ID 1 in the background.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="bind"></a>
bind - handle fish key bindings</h1>
<h2><a class="anchor" id="bind-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">bind</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-M</span> <span class="redirect">|</span> <span class="argument">--mode</span><span class="operator">)</span> <span class="argument">MODE]</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-m</span> <span class="redirect">|</span> <span class="argument">--sets-mode</span><span class="operator">)</span> <span class="argument">NEW_MODE]</span>
     <span class="argument">[</span><span class="operator">(</span><span class="argument">-k</span> <span class="redirect">|</span> <span class="argument">--key</span><span class="operator">)</span>] <span class="argument">SEQUENCE</span> <span class="argument">COMMAND</span> <span class="argument">[COMMAND...]</span>
<span class="command">bind</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-M</span> <span class="redirect">|</span> <span class="argument">--mode</span><span class="operator">)</span> <span class="argument">MODE]</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-k</span> <span class="redirect">|</span> <span class="argument">--key</span><span class="operator">)</span>] <span class="argument">SEQUENCE</span>
<span class="command">bind</span> <span class="operator">(</span><span class="argument">-K</span> <span class="redirect">|</span> <span class="argument">--key-names</span><span class="operator">)</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-a</span> <span class="redirect">|</span> <span class="argument">--all</span><span class="operator">)</span>]
<span class="command">bind</span> <span class="operator">(</span><span class="argument">-f</span> <span class="redirect">|</span> <span class="argument">--function-names</span><span class="operator">)</span>
<span class="command">bind</span> <span class="operator">(</span><span class="argument">-e</span> <span class="redirect">|</span> <span class="argument">--erase</span><span class="operator">)</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-M</span> <span class="redirect">|</span> <span class="argument">--mode</span><span class="operator">)</span> <span class="argument">MODE]</span>
     <span class="operator">(</span><span class="argument">-a</span> <span class="redirect">|</span> <span class="argument">--all</span> <span class="redirect">|</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-k</span> <span class="redirect">|</span> <span class="argument">--key</span><span class="operator">)</span>] <span class="argument">SEQUENCE</span> <span class="argument">[SEQUENCE...]</span><span class="operator">)</span>
</pre><h2><a class="anchor" id="bind-description"></a>
Description</h2>
<p><code>bind</code> adds a binding for the specified key sequence to the specified command.</p>
<p>SEQUENCE is the character sequence to bind to. These should be written as <a href="index.html#escapes">fish escape sequences</a>. For example, because pressing the Alt key and another character sends that character prefixed with an escape character, Alt-based key bindings can be written using the <code>\e</code> escape. For example, <span class="key"><em>Alt</em><span>-</span><b>w</b></span> can be written as <code>\ew</code>. The control character can be written in much the same way using the <code>\c</code> escape, for example <span class="key"><em>Control</em><span>-</span><b>X</b></span> (^X) can be written as <code>\cx</code>. Note that Alt-based key bindings are case sensitive and Control-based key bindings are not. This is a constraint of text-based terminals, not <code>fish</code>.</p>
<p>The default key binding can be set by specifying a <code>SEQUENCE</code> of the empty string (that is, <code>''</code> ). It will be used whenever no other binding matches. For most key bindings, it makes sense to use the <code>self-insert</code> function (i.e. <code>bind '' self-insert</code>) as the default keybinding. This will insert any keystrokes not specifically bound to into the editor. Non- printable characters are ignored by the editor, so this will not result in control sequences being printable.</p>
<p>If the <code>-k</code> switch is used, the name of the key (such as 'down', 'up' or 'backspace') is used instead of a sequence. The names used are the same as the corresponding curses variables, but without the 'key_' prefix. (See <code>terminfo(5)</code> for more information, or use <code>bind --key-names</code> for a list of all available named keys.)</p>
<p><code>COMMAND</code> can be any fish command, but it can also be one of a set of special input functions. These include functions for moving the cursor, operating on the kill-ring, performing tab completion, etc. Use <code>bind --function-names</code> for a complete list of these input functions.</p>
<p>When <code>COMMAND</code> is a shellscript command, it is a good practice to put the actual code into a <a href="#function">function</a> and simply bind to the function name. This way it becomes significantly easier to test the function while editing, and the result is usually more readable as well.</p>
<p>If such a script produces output, the script needs to finish by calling <code>commandline -f repaint</code> in order to tell fish that a repaint is in order.</p>
<p>When multiple <code>COMMAND</code>s are provided, they are all run in the specified order when the key is pressed.</p>
<p>If no <code>SEQUENCE</code> is provided, all bindings (or just the bindings in the specified <code>MODE</code>) are printed. If <code>SEQUENCE</code> is provided without <code>COMMAND</code>, just the binding matching that sequence is printed.</p>
<p>Key bindings are not saved between sessions by default. <b>Bare <code>bind</code> statements in <a href="index.html#initialization">config.fish</a> won't have any effect because it is sourced before the default keybindings are setup.</b> To save custom keybindings, put the <code>bind</code> statements into a function called <code>fish_user_key_bindings</code>, which will be <a href="tutorial.html#tut_autoload">autoloaded</a>.</p>
<p>Key bindings may use "modes", which mimics Vi's modal input behavior. The default mode is "default", and every bind applies to a single mode. The mode can be viewed/changed with the <code>$fish_bind_mode</code> variable.</p>
<p>The following parameters are available:</p>
<ul>
<li><code>-k</code> or <code>--key</code> Specify a key name, such as 'left' or 'backspace' instead of a character sequence</li>
<li><code>-K</code> or <code>--key-names</code> Display a list of available key names. Specifying <code>-a</code> or <code>--all</code> includes keys that don't have a known mapping</li>
<li><code>-f</code> or <code>--function-names</code> Display a list of available input functions</li>
<li><code>-M MODE</code> or <code>--mode MODE</code> Specify a bind mode that the bind is used in. Defaults to "default"</li>
<li><code>-m NEW_MODE</code> or <code>--sets-mode NEW_MODE</code> Change the current mode to <code>NEW_MODE</code> after this binding is executed</li>
<li><code>-e</code> or <code>--erase</code> Erase the binding with the given sequence and mode instead of defining a new one. Multiple sequences can be specified with this flag. Specifying <code>-a</code> or <code>--all</code> with <code>-M</code> or <code>--mode</code> erases all binds in the given mode regardless of sequence. Specifying <code>-a</code> or <code>--all</code> without <code>-M</code> or <code>--mode</code> erases all binds in all modes regardless of sequence.</li>
<li><code>-a</code> or <code>--all</code> See <code>--erase</code> and <code>--key-names</code></li>
</ul>
<p>The following special input functions are available:</p>
<ul>
<li><code>accept-autosuggestion</code>, accept the current autosuggestion completely</li>
<li><code>backward-char</code>, moves one character to the left</li>
<li><code>backward-bigword</code>, move one whitespace-delimited word to the left</li>
<li><code>backward-delete-char</code>, deletes one character of input to the left of the cursor</li>
<li><code>backward-kill-bigword</code>, move the whitespace-delimited word to the left of the cursor to the killring</li>
<li><code>backward-kill-line</code>, move everything from the beginning of the line to the cursor to the killring</li>
<li><code>backward-kill-path-component</code>, move one path component to the left of the cursor (everything from the last "/" or whitespace exclusive) to the killring</li>
<li><code>backward-kill-word</code>, move the word to the left of the cursor to the killring</li>
<li><code>backward-word</code>, move one word to the left</li>
<li><code>beginning-of-history</code>, move to the beginning of the history</li>
<li><code>beginning-of-line</code>, move to the beginning of the line</li>
<li><code>begin-selection</code>, start selecting text</li>
<li><code>capitalize-word</code>, make the current word begin with a capital letter</li>
<li><code>complete</code>, guess the remainder of the current token</li>
<li><code>complete-and-search</code>, invoke the searchable pager on completion options</li>
<li><code>delete-char</code>, delete one character to the right of the cursor</li>
<li><code>downcase-word</code>, make the current word lowercase</li>
<li><code>end-of-history</code>, move to the end of the history</li>
<li><code>end-of-line</code>, move to the end of the line</li>
<li><code>end-selection</code>, end selecting text</li>
<li><code>forward-bigword</code>, move one whitespace-delimited word to the right</li>
<li><code>forward-char</code>, move one character to the right</li>
<li><code>forward-word</code>, move one word to the right</li>
<li><code>history-search-backward</code>, search the history for the previous match</li>
<li><code>history-search-forward</code>, search the history for the next match</li>
<li><code>kill-bigword</code>, move the next whitespace-delimited word to the killring</li>
<li><code>kill-line</code>, move everything from the cursor to the end of the line to the killring</li>
<li><code>kill-selection</code>, move the selected text to the killring</li>
<li><code>kill-whole-line</code>, move the line to the killring</li>
<li><code>kill-word</code>, move the next word to the killring</li>
<li><code>suppress-autosuggestion</code>, remove the current autosuggestion</li>
<li><code>swap-selection-start-stop</code>, go to the other end of the highlighted text without changing the selection</li>
<li><code>transpose-chars</code>, transpose two characters to the left of the cursor</li>
<li><code>transpose-words</code>, transpose two words to the left of the cursor</li>
<li><code>upcase-word</code>, make the current word uppercase</li>
<li><code>yank</code>, insert the latest entry of the killring into the buffer</li>
<li><code>yank-pop</code>, rotate to the previous entry of the killring</li>
</ul>
<h2><a class="anchor" id="bind-example"></a>
Examples</h2>
 
 <pre class="fish">
<span class="command">bind</span> <span class="argument"><span>\</span>cd</span> <span class="string">'exit'</span>
</pre><p>Causes <code>fish</code> to exit when <span class="key"><em>Control</em><span>-</span><b>D</b></span> is pressed.</p>
 
 <pre class="fish">
<span class="command">bind</span> <span class="argument">-k</span> <span class="argument">ppage</span> <span class="argument">history-search-backward</span>
</pre><p>Performs a history search when the <span class="key"><b>Page Up</b></span> key is pressed.</p>
 
 <pre class="fish">
<span class="command">set</span> <span class="argument">-g</span> <span class="argument">fish_key_bindings</span> <span class="argument">fish_vi_key_bindings</span>
<span class="command">bind</span> <span class="argument">-M</span> <span class="argument">insert</span> <span class="argument"><span>\</span>cc</span> <span class="argument">kill-whole-line</span> <span class="argument">force-repaint</span>
</pre><p>Turns on Vi key bindings and rebinds <span class="key"><em>Control</em><span>-</span><b>C</b></span> to clear the input line.</p>
<h2><a class="anchor" id="special-case-escape"></a>
Special Case: The escape Character</h2>
<p>The escape key can be used standalone, for example, to switch from insertion mode to normal mode when using Vi keybindings. Escape may also be used as a "meta" key, to indicate the start of an escape sequence, such as function or arrow keys. Custom bindings can also be defined that begin with an escape character.</p>
<p>fish waits for a period after receiving the escape character, to determine whether it is standalone or part of an escape sequence. While waiting, additional key presses make the escape key behave as a meta key. If no other key presses come in, it is handled as a standalone escape. The waiting period is set to 300 milliseconds (0.3 seconds) in the default key bindings and 10 milliseconds in the vi key bindings. It can be configured by setting the <code>fish_escape_delay_ms</code> variable to a value between 10 and 5000 ms. It is recommended that this be a universal variable that you set once from an interactive session.</p>
<p>Note: fish 2.2.0 and earlier used a default of 10 milliseconds, and provided no way to configure it. That effectively made it impossible to use escape as a meta key.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="block"></a>
block - temporarily block delivery of events</h1>
<h2><a class="anchor" id="block-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">block</span> <span class="argument">[OPTIONS...]</span>
</pre><h2><a class="anchor" id="block-description"></a>
Description</h2>
<p><code>block</code> prevents events triggered by <code>fish</code> or the <a href="commands.html#emit"><code>emit</code></a> command from being delivered and acted upon while the block is in place.</p>
<p>In functions, <code>block</code> can be useful while performing work that should not be interrupted by the shell.</p>
<p>The block can be removed. Any events which triggered while the block was in place will then be delivered.</p>
<p>Event blocks should not be confused with code blocks, which are created with <code>begin</code>, <code>if</code>, <code>while</code> or <code>for</code></p>
<p>The following parameters are available:</p>
<ul>
<li><code>-l</code> or <code>--local</code> Release the block automatically at the end of the current innermost code block scope</li>
<li><code>-g</code> or <code>--global</code> Never automatically release the lock</li>
<li><code>-e</code> or <code>--erase</code> Release global block</li>
</ul>
<h2><a class="anchor" id="block-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="comment"># Create a function that listens for events</span>
<span class="command">function</span> <span class="argument">--on-event</span> <span class="argument">foo</span> <span class="argument">foo</span><span class="redirect">;</span> <span class="command">echo</span> <span class="string">'foo fired'</span><span class="redirect">;</span> <span class="command">end</span>

<span class="comment"># Block the delivery of events</span>
<span class="command">block</span> <span class="argument">-g</span>

<span class="command">emit</span> <span class="argument">foo</span>
<span class="comment"># No output will be produced</span>

<span class="command">block</span> <span class="argument">-e</span>
<span class="comment"># 'foo fired' will now be printed</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="breakpoint"></a>
breakpoint - Launch debug mode</h1>
<h2><a class="anchor" id="breakpoint-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">breakpoint</span>
</pre><h2><a class="anchor" id="breakpoint-description"></a>
Description</h2>
<p><code>breakpoint</code> is used to halt a running script and launch an interactive debugging prompt.</p>
<p>For more details, see <a href="index.html#debugging">Debugging fish scripts</a> in the <code>fish</code> manual.</p>
<p>There are no parameters for <code>breakpoint</code>.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="break"></a>
break - stop the current inner loop</h1>
<h2><a class="anchor" id="break-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="argument">LOOP_CONSTRUCT</span><span class="redirect">;</span> <span class="argument">[COMMANDS...]</span> <span class="command">break</span><span class="redirect">;</span> <span class="argument">[COMMANDS...]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="break-description"></a>
Description</h2>
<p><code>break</code> halts a currently running loop, such as a <a href="#for">for</a> loop or a <a href="#while">while</a> loop. It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement.</p>
<p>There are no parameters for <code>break</code>.</p>
<h2><a class="anchor" id="break-example"></a>
Example</h2>
<p>The following code searches all .c files for "smurf", and halts at the first occurrence.</p>
 
 <pre class="fish">
<span class="command">for</span> <span class="argument">i</span> <span class="command">in</span> <span class="file">*.c</span>
    <span class="command">if</span> <span class="binary">grep</span> <span class="argument">smurf</span> <span class="variable"><span class="operator">$</span>i</span>
        <span class="command">echo</span> <span class="argument">Smurfs</span> <span class="argument">are</span> <span class="argument">present</span> <span class="argument">in</span> <span class="variable"><span class="operator">$</span>i</span>
        <span class="command">break</span>
    <span class="command">end</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="builtin"></a>
builtin - run a builtin command</h1>
<h2><a class="anchor" id="builtin-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">builtin</span> <span class="argument">BUILTINNAME</span> <span class="argument">[OPTIONS...]</span>
</pre><h2><a class="anchor" id="builtin-description"></a>
Description</h2>
<p><code>builtin</code> forces the shell to use a builtin command, rather than a function or program.</p>
<p>The following parameters are available:</p>
<ul>
<li><code>-n</code> or <code>--names</code> List the names of all defined builtins</li>
</ul>
<h2><a class="anchor" id="builtin-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">builtin</span> <span class="command">jobs</span>
<span class="comment"># executes the jobs builtin, even if a function named jobs exists</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="case"></a>
case - conditionally execute a block of commands</h1>
<h2><a class="anchor" id="case-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">switch</span> <span class="argument">VALUE</span><span class="redirect">;</span> <span class="argument">[</span><span class="command">case</span> <span class="argument">[WILDCARD...]</span><span class="redirect">;</span> <span class="argument">[COMMANDS...]</span><span class="redirect">;</span> <span class="argument">...]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="case-description"></a>
Description</h2>
<p><code>switch</code> performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. <code>case</code> is used together with the <code>switch</code> statement in order to determine which block should be executed.</p>
<p>Each <code>case</code> command is given one or more parameters. The first <code>case</code> command with a parameter that matches the string specified in the switch command will be evaluated. <code>case</code> parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.</p>
<p>Note that fish does not fall through on case statements. Only the first matching case is executed.</p>
<p>Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter.</p>
<h2><a class="anchor" id="case-example"></a>
Example</h2>
<p>If the variable $animal contains the name of an animal, the following code would attempt to classify it:</p>
 
 <pre class="fish">
<span class="command">switch</span> <span class="variable"><span class="operator">$</span>animal</span>
    <span class="command">case</span> <span class="argument">cat</span>
        <span class="command">echo</span> <span class="argument">evil</span>
    <span class="command">case</span> <span class="argument">wolf</span> <span class="argument">dog</span> <span class="argument">human</span> <span class="argument">moose</span> <span class="argument">dolphin</span> <span class="argument">whale</span>
        <span class="command">echo</span> <span class="argument">mammal</span>
    <span class="command">case</span> <span class="argument">duck</span> <span class="argument">goose</span> <span class="argument">albatross</span>
        <span class="command">echo</span> <span class="argument">bird</span>
    <span class="command">case</span> <span class="argument">shark</span> <span class="argument">trout</span> <span class="argument">stingray</span>
        <span class="command">echo</span> <span class="argument">fish</span>
    <span class="comment"># Note that the next case has a wildcard which is quoted</span>
    <span class="command">case</span> <span class="string">'*'</span>
        <span class="command">echo</span> <span class="argument">I</span> <span class="argument">have</span> <span class="argument">no</span> <span class="argument">idea</span> <span class="argument">what</span> <span class="argument">a</span> <span class="variable"><span class="operator">$</span>animal</span> <span class="argument">is</span>
<span class="command">end</span>
</pre><p>If the above code was run with <code>$animal</code> set to <code>whale</code>, the output would be <code>mammal</code>.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="cd"></a>
cd - change directory</h1>
<h2><a class="anchor" id="cd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">cd</span> <span class="argument">[DIRECTORY]</span>
</pre><h2><a class="anchor" id="cd-description"></a>
Description</h2>
<p><code>cd</code> changes the current working directory.</p>
<p>If <code>DIRECTORY</code> is supplied, it will become the new directory. If no parameter is given, the contents of the <code>HOME</code> environment variable will be used.</p>
<p>If <code>DIRECTORY</code> is a relative path, the paths found in the <code>CDPATH</code> environment variable array will be tried as prefixes for the specified path.</p>
<p>Note that the shell will attempt to change directory without requiring <code>cd</code> if the name of a directory is provided (starting with <code>.</code>, <code>/</code> or <code>~</code>, or ending with <code>/</code>).</p>
<p>Fish also ships a wrapper function around the builtin <code>cd</code> that understands <code>cd -</code> as changing to the previous directory. See also <a href="commands.html#prevd"><code>prevd</code></a>. This wrapper function maintains a history of the 25 most recently visited directories in the <code>$dirprev</code> and <code>$dirnext</code> global variables.</p>
<h2><a class="anchor" id="cd-example"></a>
Examples</h2>
 
 <pre class="fish">
<span class="command">cd</span>
<span class="comment"># changes the working directory to your home directory.</span>

<span class="command">cd</span> <span class="path">/usr/src/fish-shell</span>
<span class="comment"># changes the working directory to /usr/src/fish-shell</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="commandline"></a>
commandline - set or get the current command line buffer</h1>
<h2><a class="anchor" id="commandline-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">commandline</span> <span class="argument">[OPTIONS]</span> <span class="argument">[CMD]</span>
</pre><h2><a class="anchor" id="commandline-description"></a>
Description</h2>
<p><code>commandline</code> can be used to set or get the current contents of the command line buffer.</p>
<p>With no parameters, <code>commandline</code> returns the current value of the command line.</p>
<p>With <code>CMD</code> specified, the command line buffer is erased and replaced with the contents of <code>CMD</code>.</p>
<p>The following options are available:</p>
<ul>
<li><code>-C</code> or <code>--cursor</code> set or get the current cursor position, not the contents of the buffer. If no argument is given, the current cursor position is printed, otherwise the argument is interpreted as the new cursor position.</li>
<li><code>-f</code> or <code>--function</code> inject readline functions into the reader. This option cannot be combined with any other option. It will cause any additional arguments to be interpreted as readline functions, and these functions will be injected into the reader, so that they will be returned to the reader before any additional actual key presses are read.</li>
</ul>
<p>The following options change the way <code>commandline</code> updates the command line buffer:</p>
<ul>
<li><code>-a</code> or <code>--append</code> do not remove the current commandline, append the specified string at the end of it</li>
<li><code>-i</code> or <code>--insert</code> do not remove the current commandline, insert the specified string at the current cursor position</li>
<li><code>-r</code> or <code>--replace</code> remove the current commandline and replace it with the specified string (default)</li>
</ul>
<p>The following options change what part of the commandline is printed or updated:</p>
<ul>
<li><code>-b</code> or <code>--current-buffer</code> select the entire buffer (default)</li>
<li><code>-j</code> or <code>--current-job</code> select the current job</li>
<li><code>-p</code> or <code>--current-process</code> select the current process</li>
<li><code>-t</code> or <code>--current-token</code> select the current token.</li>
</ul>
<p>The following options change the way <code>commandline</code> prints the current commandline buffer:</p>
<ul>
<li><code>-c</code> or <code>--cut-at-cursor</code> only print selection up until the current cursor position</li>
<li><code>-o</code> or <code>--tokenize</code> tokenize the selection and print one string-type token per line</li>
</ul>
<p>If <code>commandline</code> is called during a call to complete a given string using <code>complete -C STRING</code>, <code>commandline</code> will consider the specified string to be the current contents of the command line.</p>
<p>The following options output metadata about the commandline state:</p>
<ul>
<li><code>-L</code> or <code>--line</code> print the line that the cursor is on, with the topmost line starting at 1</li>
<li><code>-S</code> or <code>--search-mode</code> evaluates to true if the commandline is performing a history search</li>
<li><code>-P</code> or <code>--paging-mode</code> evaluates to true if the commandline is showing pager contents, such as tab completions</li>
</ul>
<h2><a class="anchor" id="commandline-example"></a>
Example</h2>
<p><code>commandline -j $history[3]</code> replaces the job under the cursor with the third item from the command line history.</p>
<p>If the commandline contains </p> 
 <pre class="fish">
<span class="prompt">&gt;</span> <span class="command">echo</span> <span class="variable"><span class="operator">$</span>fl</span><span class="cursor">o</span><span class="argument">under</span> <span class="redirect">&gt;&amp;2</span> <span class="redirect">|</span> <span class="binary">less</span><span class="redirect">;</span> <span class="command">and</span> <span class="command">echo</span> <span class="variable"><span class="operator">$</span>catfish</span>
</pre><p>(with the cursor on the "o" of "flounder")</p>
<p>Then the following invocations behave like this: </p> 
 <pre class="fish">
<span class="prompt">&gt;</span> <span class="command">commandline</span> <span class="argument">-t</span>
<span class="variable"><span class="operator">$</span>flounder</span>
<span class="prompt">&gt;</span> <span class="command">commandline</span> <span class="argument">-ct</span>
<span class="variable"><span class="operator">$</span>fl</span>
<span class="prompt">&gt;</span> <span class="command">commandline</span> <span class="argument">-b</span> <span class="comment">## or just commandline</span>
<span class="command">echo</span> <span class="variable"><span class="operator">$</span>flounder</span> <span class="redirect">&gt;&amp;2</span> <span class="redirect">|</span> <span class="binary">less</span><span class="redirect">;</span> <span class="command">and</span> <span class="command">echo</span> <span class="variable"><span class="operator">$</span>catfish</span>
<span class="prompt">&gt;</span> <span class="command">commandline</span> <span class="argument">-p</span>
<span class="command">echo</span> <span class="variable"><span class="operator">$</span>flounder</span> <span class="redirect">&gt;&amp;2</span>
<span class="prompt">&gt;</span> <span class="command">commandline</span> <span class="argument">-j</span>
<span class="command">echo</span> <span class="variable"><span class="operator">$</span>flounder</span> <span class="redirect">&gt;&amp;2</span> <span class="redirect">|</span> <span class="binary">less</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="command"></a>
command - run a program</h1>
<h2><a class="anchor" id="command-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">command</span> <span class="argument">[OPTIONS]</span> <span class="argument">COMMANDNAME</span> <span class="argument">[ARGS...]</span>
</pre><h2><a class="anchor" id="command-description"></a>
Description</h2>
<p><code>command</code> forces the shell to execute the program <code>COMMANDNAME</code> and ignore any functions or builtins with the same name.</p>
<p>The following options are available:</p>
<ul>
<li><code>-s</code> or <code>--search</code> returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the <code>$PATH</code>.</li>
</ul>
<p>With the <code>-s</code> option, <code>command</code> treats every argument as a separate command to look up and sets the exit status to 0 if any of the specified commands were found, or 1 if no commands could be found.</p>
<p>For basic compatibility with POSIX <code>command</code>, the <code>-v</code> flag is recognized as an alias for <code>-s</code>.</p>
<h2><a class="anchor" id="command-example"></a>
Examples</h2>
<p><code>command ls</code> causes fish to execute the <code>ls</code> program, even if an <code>ls</code> function exists.</p>
<p><code>command -s ls</code> returns the path to the <code>ls</code> program.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="complete"></a>
complete - edit command specific tab-completions</h1>
<h2><a class="anchor" id="complete-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">complete</span> <span class="operator">(</span> <span class="argument">-c</span> <span class="redirect">|</span> <span class="argument">--command</span> <span class="redirect">|</span> <span class="argument">-p</span> <span class="redirect">|</span> <span class="argument">--path</span> <span class="operator">)</span> <span class="argument">COMMAND</span>
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-c</span> <span class="redirect">|</span> <span class="argument">--command</span> <span class="redirect">|</span> <span class="argument">-p</span> <span class="redirect">|</span> <span class="argument">--path</span> <span class="operator">)</span> <span class="argument">COMMAND]</span>...
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-e</span> <span class="redirect">|</span> <span class="argument">--erase</span> <span class="operator">)</span>]
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-s</span> <span class="redirect">|</span> <span class="argument">--short-option</span> <span class="operator">)</span> <span class="argument">SHORT_OPTION]</span>...
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-l</span> <span class="redirect">|</span> <span class="argument">--long-option</span> <span class="redirect">|</span> <span class="argument">-o</span> <span class="redirect">|</span> <span class="argument">--old-option</span> <span class="operator">)</span> <span class="argument">LONG_OPTION]</span>...
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-a</span> <span class="redirect">|</span> <span class="argument">--arguments</span> <span class="operator">)</span> <span class="argument">OPTION_ARGUMENTS]</span>
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-f</span> <span class="redirect">|</span> <span class="argument">--no-files</span> <span class="operator">)</span>]
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-r</span> <span class="redirect">|</span> <span class="argument">--require-parameter</span> <span class="operator">)</span>]
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-x</span> <span class="redirect">|</span> <span class="argument">--exclusive</span> <span class="operator">)</span>]
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-w</span> <span class="redirect">|</span> <span class="argument">--wraps</span> <span class="operator">)</span> <span class="argument">WRAPPED_COMMAND]</span>...
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-n</span> <span class="redirect">|</span> <span class="argument">--condition</span> <span class="operator">)</span> <span class="argument">CONDITION]</span>
        <span class="argument">[</span><span class="operator">(</span> <span class="argument">-d</span> <span class="redirect">|</span> <span class="argument">--description</span> <span class="operator">)</span> <span class="argument">DESCRIPTION]</span>
<span class="command">complete</span> <span class="operator">(</span> <span class="argument">-C</span><span class="argument">[STRING]</span> <span class="redirect">|</span> <span class="argument">--do-complete</span>[=STRING] <span class="operator">)</span>
</pre><h2><a class="anchor" id="complete-description"></a>
Description</h2>
<p>For an introduction to specifying completions, see <a href="index.html#completion-own">Writing your own completions</a> in the fish manual.</p>
<ul>
<li><code>COMMAND</code> is the name of the command for which to add a completion.</li>
<li><code>SHORT_OPTION</code> is a one character option for the command.</li>
<li><code>LONG_OPTION</code> is a multi character option for the command.</li>
<li><code>OPTION_ARGUMENTS</code> is parameter containing a space-separated list of possible option-arguments, which may contain command substitutions.</li>
<li><code>DESCRIPTION</code> is a description of what the option and/or option arguments do.</li>
<li><code>-c COMMAND</code> or <code>--command COMMAND</code> specifies that <code>COMMAND</code> is the name of the command.</li>
<li><code>-p COMMAND</code> or <code>--path COMMAND</code> specifies that <code>COMMAND</code> is the absolute path of the program (optionally containing wildcards).</li>
<li><code>-e</code> or <code>--erase</code> deletes the specified completion.</li>
<li><code>-s SHORT_OPTION</code> or <code>--short-option=SHORT_OPTION</code> adds a short option to the completions list.</li>
<li><code>-l LONG_OPTION</code> or <code>--long-option=LONG_OPTION</code> adds a GNU style long option to the completions list.</li>
<li><code>-o LONG_OPTION</code> or <code>--old-option=LONG_OPTION</code> adds an old style long option to the completions list (See below for details).</li>
<li><code>-a OPTION_ARGUMENTS</code> or <code>--arguments=OPTION_ARGUMENTS</code> adds the specified option arguments to the completions list.</li>
<li><code>-f</code> or <code>--no-files</code> specifies that the options specified by this completion may not be followed by a filename.</li>
<li><code>-r</code> or <code>--require-parameter</code> specifies that the options specified by this completion always must have an option argument, i.e. may not be followed by another option.</li>
<li><code>-x</code> or <code>--exclusive</code> implies both <code>-r</code> and <code>-f</code>.</li>
<li><code>-w WRAPPED_COMMAND</code> or <code>--wraps=WRAPPED_COMMAND</code> causes the specified command to inherit completions from the wrapped command (See blow for details).</li>
<li><code>-n</code> or <code>--condition</code> specifies a shell command that must return 0 if the completion is to be used. This makes it possible to specify completions that should only be used in some cases.</li>
<li><code>-CSTRING</code> or <code>--do-complete=STRING</code> makes complete try to find all possible completions for the specified string.</li>
<li><code>-C</code> or <code>--do-complete</code> with no argument makes complete try to find all possible completions for the current command line buffer. If the shell is not in interactive mode, an error is returned.</li>
</ul>
<p>Command specific tab-completions in <code>fish</code> are based on the notion of options and arguments. An option is a parameter which begins with a hyphen, such as '<code>-h</code>', '<code>-help</code>' or '<code>--help</code>'. Arguments are parameters that do not begin with a hyphen. Fish recognizes three styles of options, the same styles as the GNU version of the getopt library. These styles are:</p>
<ul>
<li>Short options, like '<code>-a</code>'. Short options are a single character long, are preceded by a single hyphen and may be grouped together (like '<code>-la</code>', which is equivalent to '<code>-l -a</code>'). Option arguments may be specified in the following parameter ('<code>-w 32</code>') or by appending the option with the value ('<code>-w32</code>').</li>
<li>Old style long options, like '<code>-Wall</code>'. Old style long options can be more than one character long, are preceded by a single hyphen and may not be grouped together. Option arguments are specified in the following parameter ('<code>-ao null</code>').</li>
<li>GNU style long options, like '<code>--colors</code>'. GNU style long options can be more than one character long, are preceded by two hyphens, and may not be grouped together. Option arguments may be specified in the following parameter ('<code>--quoting-style shell</code>') or by appending the option with a '<code>=</code>' and the value ('<code>--quoting-style=shell</code>'). GNU style long options may be abbreviated so long as the abbreviation is unique ('<code>--h</code>') is equivalent to '<code>--help</code>' if help is the only long option beginning with an 'h').</li>
</ul>
<p>The options for specifying command name and command path may be used multiple times to define the same completions for multiple commands.</p>
<p>The options for specifying command switches and wrapped commands may be used multiple times to define multiple completions for the command(s) in a single call.</p>
<p>Invoking <code>complete</code> multiple times for the same command adds the new definitions on top of any existing completions defined for the command.</p>
<p>When <code>-a</code> or <code>--arguments</code> is specified in conjunction with long, short, or old style options, the specified arguments are only used as completions when attempting to complete an argument for any of the specified options. If <code>-a</code> or <code>--arguments</code> is specified without any long, short, or old style options, the specified arguments are used when completing any argument to the command (except when completing an option argument that was specified with <code>-r</code> or <code>--require-parameter</code>).</p>
<p>Command substitutions found in <code>OPTION_ARGUMENTS</code> are not expected to return a space-separated list of arguments. Instead they must return a newline-separated list of arguments, and each argument may optionally have a tab character followed by the argument description. Any description provided in this way overrides a description given with <code>-d</code> or <code>--description</code>.</p>
<p>The <code>-w</code> or <code>--wraps</code> options causes the specified command to inherit completions from another command. The inheriting command is said to "wrap" the inherited command. The wrapping command may have its own completions in addition to inherited ones. A command may wrap multiple commands, and wrapping is transitive: if A wraps B, and B wraps C, then A automatically inherits all of C's completions. Wrapping can be removed using the <code>-e</code> or <code>--erase</code> options. Note that wrapping only works for completions specified with <code>-c</code> or <code>--command</code> and are ignored when specifying completions with <code>-p</code> or <code>--path</code>.</p>
<p>When erasing completions, it is possible to either erase all completions for a specific command by specifying <code>complete -c COMMAND -e</code>, or by specifying a specific completion option to delete by specifying either a long, short or old style option.</p>
<h2><a class="anchor" id="complete-example"></a>
Example</h2>
<p>The short style option <code>-o</code> for the <code>gcc</code> command requires that a file follows it. This can be done using writing:</p>
 
 <pre class="fish">
<span class="command">complete</span> <span class="argument">-c</span> <span class="argument">gcc</span> <span class="argument">-s</span> <span class="argument">o</span> <span class="argument">-r</span>
</pre><p>The short style option <code>-d</code> for the <code>grep</code> command requires that one of the strings '<code>read</code>', '<code>skip</code>' or '<code>recurse</code>' is used. This can be specified writing:</p>
 
 <pre class="fish">
<span class="command">complete</span> <span class="argument">-c</span> <span class="argument">grep</span> <span class="argument">-s</span> <span class="argument">d</span> <span class="argument">-x</span> <span class="argument">-a</span> <span class="string">"read skip recurse"</span>
</pre><p>The <code>su</code> command takes any username as an argument. Usernames are given as the first colon-separated field in the file /etc/passwd. This can be specified as:</p>
 
 <pre class="fish">
<span class="command">complete</span> <span class="argument">-x</span> <span class="argument">-c</span> <span class="argument">su</span> <span class="argument">-d</span> <span class="string">"Username"</span> <span class="argument">-a</span> <span class="string">"<span class="operator">(</span>cat /etc/passwd | cut -d : -f 1<span class="operator">)</span>"</span>
</pre><p>The <code>rpm</code> command has several different modes. If the <code>-e</code> or <code>--erase</code> flag has been specified, <code>rpm</code> should delete one or more packages, in which case several switches related to deleting packages are valid, like the <code>nodeps</code> switch.</p>
<p>This can be written as:</p>
 
 <pre class="fish">
<span class="command">complete</span> <span class="argument">-c</span> <span class="argument">rpm</span> <span class="argument">-n</span> <span class="string">"__fish_contains_opt -s e erase"</span> <span class="argument">-d</span> <span class="argument">nodeps</span> <span class="string">"Don't check dependencies"</span>
</pre><p>where <code>__fish_contains_opt</code> is a function that checks the command line buffer for the presence of a specified set of options.</p>
<p>To implement an alias, use the <code>-w</code> or <code>--wraps</code> option:</p>
 
 <pre class="fish">
<span class="command">complete</span> <span class="argument">-c</span> <span class="argument">hub</span> <span class="argument">-w</span> <span class="argument">git</span>
</pre><p>Now hub inherits all of the completions from git. Note this can also be specified in a function declaration.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="contains"></a>
contains - test if a word is present in a list</h1>
<h2><a class="anchor" id="contains-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">contains</span> <span class="argument">[OPTIONS]</span> <span class="argument">KEY</span> <span class="argument">[VALUES...]</span>
</pre><h2><a class="anchor" id="contains-description"></a>
Description</h2>
<p><code>contains</code> tests whether the set <code>VALUES</code> contains the string <code>KEY</code>. If so, <code>contains</code> exits with status 0; if not, it exits with status 1.</p>
<p>The following options are available:</p>
<ul>
<li><code>-i</code> or <code>--index</code> print the word index</li>
</ul>
<p>Note that, like GNU tools, <code>contains</code> interprets all arguments starting with a <code>-</code> as options to contains, until it reaches an argument that is <code>--</code> (two dashes). See the examples below.</p>
<h2><a class="anchor" id="contains-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">for</span> <span class="argument">i</span> <span class="command">in</span> <span class="path">~/bin</span> <span class="path">/usr/local/bin</span>
    <span class="command">if</span> <span class="command">not</span> <span class="command">contains</span> <span class="variable"><span class="operator">$</span>i</span> <span class="variable"><span class="operator">$</span>PATH</span>
        <span class="command">set</span> <span class="argument">PATH</span> <span class="variable"><span class="operator">$</span>PATH</span> <span class="variable"><span class="operator">$</span>i</span>
    <span class="command">end</span>
<span class="command">end</span>
</pre><p>The above code tests if <code>~/bin</code> and <code>/usr/local/bin</code> are in the path and adds them if not.</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">hasargs</span>
    <span class="command">if</span> <span class="command">contains</span> <span class="argument">--</span> <span class="argument">-q</span> <span class="variable"><span class="operator">$</span>argv</span>
        <span class="command">echo</span> <span class="string">'$argv contains a -q option'</span>
    <span class="command">end</span>
<span class="command">end</span>
</pre><p>The above code checks for <code>-q</code> in the argument list, using the <code>--</code> argument to demarcate options to <code>contains</code> from the key to search for.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="continue"></a>
continue - skip the remainder of the current iteration of the current inner loop</h1>
<h2><a class="anchor" id="continue-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="argument">LOOP_CONSTRUCT</span><span class="redirect">;</span> <span class="argument">[COMMANDS...;]</span> <span class="command">continue</span><span class="redirect">;</span> <span class="argument">[COMMANDS...;]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="continue-description"></a>
Description</h2>
<p><code>continue</code> skips the remainder of the current iteration of the current inner loop, such as a <a href="#for">for</a> loop or a <a href="#while">while</a> loop. It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement.</p>
<h2><a class="anchor" id="continue-example"></a>
Example</h2>
<p>The following code removes all tmp files that do not contain the word smurf.</p>
 
 <pre class="fish">
<span class="command">for</span> <span class="argument">i</span> <span class="command">in</span> <span class="file">*.tmp</span>
    <span class="command">if</span> <span class="binary">grep</span> <span class="argument">smurf</span> <span class="variable"><span class="operator">$</span>i</span>
        <span class="command">continue</span>
    <span class="command">end</span>
    <span class="binary">rm</span> <span class="variable"><span class="operator">$</span>i</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="count"></a>
count - count the number of elements of an array</h1>
<h2><a class="anchor" id="count-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">count</span> <span class="variable"><span class="operator">$</span>VARIABLE</span>
</pre><h2><a class="anchor" id="count-description"></a>
Description</h2>
<p><code>count</code> prints the number of arguments that were passed to it. This is usually used to find out how many elements an environment variable array contains.</p>
<p><code>count</code> does not accept any options, including <code>-h</code> or <code>--help</code>.</p>
<p><code>count</code> exits with a non-zero exit status if no arguments were passed to it, and with zero if at least one argument was passed.</p>
<h2><a class="anchor" id="count-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">count</span> <span class="variable"><span class="operator">$</span>PATH</span>
<span class="comment"># Returns the number of directories in the users PATH variable.</span>

<span class="command">count</span> <span class="file">*.txt</span>
<span class="comment"># Returns the number of files in the current working directory ending with the suffix '.txt'.</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="dirh"></a>
dirh - print directory history</h1>
<h2><a class="anchor" id="dirh-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">dirh</span>
</pre><h2><a class="anchor" id="dirh-description"></a>
Description</h2>
<p><code>dirh</code> prints the current directory history. The current position in the history is highlighted using the color defined in the <code>fish_color_history_current</code> environment variable.</p>
<p><code>dirh</code> does not accept any parameters.</p>
<p>Note that the <code>cd</code> command limits directory history to the 25 most recently visited directories. The history is stored in the <code>$dirprev</code> and <code>$dirnext</code> variables.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="dirs"></a>
dirs - print directory stack</h1>
<h2><a class="anchor" id="dirs-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">dirs</span>
<span class="command">dirs</span> <span class="argument">-c</span>
</pre><h2><a class="anchor" id="dirs-description"></a>
Description</h2>
<p><code>dirs</code> prints the current directory stack, as created by the <a href="#pushd"><code>pushd</code></a> command.</p>
<p>With "-c", it clears the directory stack instead.</p>
<p><code>dirs</code> does not accept any parameters.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="echo"></a>
echo - display a line of text</h1>
<h2><a class="anchor" id="echo-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">echo</span> <span class="argument">[OPTIONS]</span> <span class="argument">[STRING]</span>
</pre><h2><a class="anchor" id="echo-description"></a>
Description</h2>
<p><code>echo</code> displays a string of text.</p>
<p>The following options are available:</p>
<ul>
<li><code>-n</code>, Do not output a newline</li>
<li><code>-s</code>, Do not separate arguments with spaces</li>
<li><code>-E</code>, Disable interpretation of backslash escapes (default)</li>
<li><code>-e</code>, Enable interpretation of backslash escapes</li>
</ul>
<h2><a class="anchor" id="echo-escapes"></a>
Escape Sequences</h2>
<p>If <code>-e</code> is used, the following sequences are recognized:</p>
<ul>
<li><code>\</code> backslash</li>
<li><code>\a</code> alert (BEL)</li>
<li><code>\b</code> backspace</li>
<li><code>\c</code> produce no further output</li>
<li><code>\e</code> escape</li>
<li><code>\f</code> form feed</li>
<li><code>\n</code> new line</li>
<li><code>\r</code> carriage return</li>
<li><code>\t</code> horizontal tab</li>
<li><code>\v</code> vertical tab</li>
<li><code>\0NNN</code> byte with octal value NNN (1 to 3 digits)</li>
<li><code>\xHH</code> byte with hexadecimal value HH (1 to 2 digits)</li>
</ul>
<h2><a class="anchor" id="echo-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">echo</span> <span class="string">'Hello World'</span>
</pre><p>Print hello world to stdout</p>
 
 <pre class="fish">
<span class="command">echo</span> <span class="argument">-e</span> <span class="string">'Top<span>\</span>nBottom'</span>
</pre><p>Print Top and Bottom on separate lines, using an escape sequence</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="else"></a>
else - execute command if a condition is not met</h1>
<h2><a class="anchor" id="else-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">if</span> <span class="argument">CONDITION</span><span class="redirect">;</span> <span class="argument">COMMANDS_TRUE...</span><span class="redirect">;</span> <span class="argument">[<span class="command">else</span><span class="redirect">;</span> <span class="argument">COMMANDS_FALSE...</span>;]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="else-description"></a>
Description</h2>
<p><code>if</code> will execute the command <code>CONDITION</code>. If the condition's exit status is 0, the commands <code>COMMANDS_TRUE</code> will execute. If it is not 0 and <code>else</code> is given, <code>COMMANDS_FALSE</code> will be executed.</p>
<h2><a class="anchor" id="else-example"></a>
Example</h2>
<p>The following code tests whether a file <code>foo.txt</code> exists as a regular file.</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="argument">-f</span> <span class="file">foo.txt</span>
    <span class="command">echo</span> <span class="argument">foo.txt</span> <span class="argument">exists</span>
<span class="command">else</span>
    <span class="command">echo</span> <span class="argument">foo.txt</span> <span class="argument">does</span> <span class="argument">not</span> <span class="argument">exist</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="emit"></a>
emit - Emit a generic event</h1>
<h2><a class="anchor" id="emit-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">emit</span> <span class="argument">EVENT_NAME</span> <span class="argument">[ARGUMENTS...]</span>
</pre><h2><a class="anchor" id="emit-description"></a>
Description</h2>
<p><code>emit</code> emits, or fires, an event. Events are delivered to, or caught by, special functions called event handlers. The arguments are passed to the event handlers as function arguments.</p>
<h2><a class="anchor" id="emit-example"></a>
Example</h2>
<p>The following code first defines an event handler for the generic event named 'test_event', and then emits an event of that type.</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">event_test</span> <span class="argument">--on-event</span> <span class="argument">test_event</span>
    <span class="command">echo</span> <span class="argument">event</span> <span class="argument">test:</span> <span class="variable"><span class="operator">$</span>argv</span>
<span class="command">end</span>

<span class="command">emit</span> <span class="argument">test_event</span> <span class="argument">something</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="end"></a>
end - end a block of commands.</h1>
<h2><a class="anchor" id="end-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">begin</span><span class="redirect">;</span> <span class="argument">[COMMANDS...]</span> <span class="command">end</span>
<span class="command">if</span> <span class="argument">CONDITION</span><span class="redirect">;</span> <span class="argument">COMMANDS_TRUE...</span><span class="redirect">;</span> <span class="argument">[<span class="command">else</span><span class="redirect">;</span> <span class="argument">COMMANDS_FALSE...</span>;]</span> <span class="command">end</span>
<span class="command">while</span> <span class="argument">CONDITION</span><span class="redirect">;</span> <span class="argument">COMMANDS...</span><span class="redirect">;</span> <span class="command">end</span>
<span class="command">for</span> <span class="argument">VARNAME</span> <span class="command">in</span> <span class="argument">[VALUES...]</span><span class="redirect">;</span> <span class="argument">COMMANDS...</span><span class="redirect">;</span> <span class="command">end</span>
<span class="command">switch</span> <span class="argument">VALUE</span><span class="redirect">;</span> <span class="argument">[</span><span class="command">case</span> <span class="argument">[WILDCARD...]</span><span class="redirect">;</span> <span class="argument">[COMMANDS...]</span><span class="redirect">;</span> <span class="argument">...]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="end-description"></a>
Description</h2>
<p><code>end</code> ends a block of commands.</p>
<p>For more information, read the documentation for the block constructs, such as <code>if</code>, <code>for</code> and <code>while</code>.</p>
<p>The <code>end</code> command does not change the current exit status.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="eval"></a>
eval - evaluate the specified commands</h1>
<h2><a class="anchor" id="eval-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">eval</span> <span class="argument">[COMMANDS...]</span>
</pre><h2><a class="anchor" id="eval-description"></a>
Description</h2>
<p><code>eval</code> evaluates the specified parameters as a command. If more than one parameter is specified, all parameters will be joined using a space character as a separator.</p>
<h2><a class="anchor" id="eval-example"></a>
Example</h2>
<p>The following code will call the ls command. Note that <code>fish</code> does not support the use of shell variables as direct commands; <code>eval</code> can be used to work around this.</p>
 
 <pre class="fish">
<span class="command">set</span> <span class="argument">cmd</span> <span class="argument">ls</span>
<span class="command">eval</span> <span class="variable"><span class="operator">$</span>cmd</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="exec"></a>
exec - execute command in current process</h1>
<h2><a class="anchor" id="exec-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">exec</span> <span class="argument">COMMAND</span> <span class="argument">[OPTIONS...]</span>
</pre><h2><a class="anchor" id="exec-description"></a>
Description</h2>
<p><code>exec</code> replaces the currently running shell with a new command. On successful completion, <code>exec</code> never returns. <code>exec</code> cannot be used inside a pipeline.</p>
<h2><a class="anchor" id="exec-example"></a>
Example</h2>
<p><code>exec emacs</code> starts up the emacs text editor, and exits <code>fish</code>. When emacs exits, the session will terminate.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="exit"></a>
exit - exit the shell</h1>
<h2><a class="anchor" id="exit-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">exit</span> <span class="argument">[STATUS]</span>
</pre><h2><a class="anchor" id="exit-description"></a>
Description</h2>
<p><code>exit</code> causes fish to exit. If <code>STATUS</code> is supplied, it will be converted to an integer and used as the exit code. Otherwise, the exit code will be that of the last command executed.</p>
<p>If exit is called while sourcing a file (using the <a href="#source">source</a> builtin) the rest of the file will be skipped, but the shell itself will not exit.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="false"></a>
false - return an unsuccessful result</h1>
<h2><a class="anchor" id="false-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">false</span>
</pre><h2><a class="anchor" id="false-description"></a>
Description</h2>
<p><code>false</code> sets the exit status to 1.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fg"></a>
fg - bring job to foreground</h1>
<h2><a class="anchor" id="fg-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">fg</span> <span class="argument">[PID]</span>
</pre><h2><a class="anchor" id="fg-description"></a>
Description</h2>
<p><code>fg</code> brings the specified <a href="index.html#syntax-job-control">job</a> to the foreground, resuming it if it is stopped. While a foreground job is executed, fish is suspended. If no job is specified, the last job to be used is put in the foreground. If PID is specified, the job with the specified group ID is put in the foreground.</p>
<p>The PID of the desired process is usually found by using <a href="index.html#expand-process">process expansion</a>.</p>
<h2><a class="anchor" id="fg-example"></a>
Example</h2>
<p><code>fg %1</code> will put the job with job ID 1 in the foreground.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_config"></a>
fish_config - start the web-based configuration interface</h1>
<h2><a class="anchor" id="fish_config-description"></a>
Description</h2>
<p><code>fish_config</code> starts the web-based configuration interface.</p>
<p>The web interface allows you to view your functions, variables and history, and to make changes to your prompt and color configuration.</p>
<p><code>fish_config</code> starts a local web server and then opens a web browser window; when you have finished, close the browser window and then press the Enter key to terminate the configuration session.</p>
<p><code>fish_config</code> optionally accepts name of the initial configuration tab. For e.g. <code>fish_config history</code> will start configuration interface with history tab.</p>
<p>If the <code>BROWSER</code> environment variable is set, it will be used as the name of the web browser to open instead of the system default.</p>
<h2><a class="anchor" id="fish_config-example"></a>
Example</h2>
<p><code>fish_config</code> opens a new web browser window and allows you to configure certain fish settings.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_indent"></a>
fish_indent - indenter and prettifier</h1>
<h2><a class="anchor" id="fish_indent-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">fish_indent</span> <span class="argument">[OPTIONS]</span>
</pre><h2><a class="anchor" id="fish_indent-description"></a>
Description</h2>
<p><code>fish_indent</code> is used to indent a piece of fish code. <code>fish_indent</code> reads commands from standard input and outputs them to standard output.</p>
<p>The following options are available:</p>
<ul>
<li><code>-d</code> or <code>--dump</code> dumps information about the parsed fish commands to stderr</li>
<li><code>-i</code> or <code>--no-indent</code> do not indent commands; only reformat to one job per line</li>
<li><code>-v</code> or <code>--version</code> displays the current fish version and then exits</li>
<li><code>--ansi</code> colorizes the output using ANSI escape sequences, appropriate for the current $TERM, using the colors defined in the environment (such as <code>$fish_color_command</code>).</li>
<li><code>--html</code> outputs HTML, which supports syntax highlighting if the appropriate CSS is defined. The CSS class names are the same as the variable names, such as <code>fish_color_command</code></li>
</ul>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_key_reader"></a>
fish_key_reader - explore what characters keyboard keys send</h1>
<h2><a class="anchor" id="fish_key_reader-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">fish_key_reader</span> <span class="argument">[</span><span class="argument">-c</span>] <span class="argument">[</span><span class="argument">-d</span> <span class="argument">LEVEL]</span>
</pre><h2><a class="anchor" id="fish_key_reader-description"></a>
Description</h2>
<p><code>fish_key_reader</code> is used to study input received from the terminal and can help with key binds. The program is interactive and works on standard input. Individual characters themselves and their hexadecimal values are displayed.</p>
<p>The tool will output an example <code>bind</code> command matching the character sequence captured. If the character sequence matches a special key name (see <code>bind --key-names</code>), both <code>bind CHARS ...</code> and <code>bind -k KEYNAME ...</code> usage will be shown.</p>
<p>The following parameters are available:</p>
<ul>
<li><code>-c</code> or <code>--continuous</code> begins a session where multiple key sequences can be inspected. By default the program exits after capturing a single key sequence.</li>
<li><code>-d</code> or <code>--debug-level=DEBUG_LEVEL</code> enables debug output and specifies a verbosity level (like <code>fish -d</code>). Defaults to 0.</li>
</ul>
<p>In continuous mode (<code>-c</code>), the delay in milliseconds since the previous character was received is also shown. This information may be useful to determine a preferred <code>fish_escape_delay_ms</code> setting or learn the amount of lag introduced by <code>ssh</code> or <code>tmux</code>.</p>
<p><code>fish_key_reader</code> intentionally disables handling of many signals. To terminate <code>fish_key_reader</code> in a <code>--continuous</code> run:</p><ul>
<li>press <code>Ctrl-C</code> twice, or</li>
<li>press <code>Ctrl-D</code> twice, or</li>
<li>type <code>exit</code>, or</li>
<li>type <code>quit</code></li>
</ul>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_prompt"></a>
fish_prompt - define the appearance of the command line prompt</h1>
<h2><a class="anchor" id="fish_prompt-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">function</span> <span class="argument">fish_prompt</span>
    <span class="argument">...</span>
<span class="command">end</span>
</pre><h2><a class="anchor" id="fish_prompt-description"></a>
Description</h2>
<p>By defining the <code>fish_prompt</code> function, the user can choose a custom prompt. The <code>fish_prompt</code> function is executed when the prompt is to be shown, and the output is used as a prompt.</p>
<p>The exit status of commands within <code>fish_prompt</code> will not modify the value of <a href="index.html#variables-status">$status</a> outside of the <code>fish_prompt</code> function.</p>
<p><code>fish</code> ships with a number of example prompts that can be chosen with the <code>fish_config</code> command.</p>
<h2><a class="anchor" id="fish_prompt-example"></a>
Example</h2>
<p>A simple prompt:</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">fish_prompt</span> <span class="argument">-d</span> <span class="string">"Write out the prompt"</span>
    <span class="command">printf</span> <span class="string">'<span>%</span>s<span>@</span><span>%</span>s<span>%</span>s<span>%</span>s<span>%</span>s&gt; '</span> <span class="operator">(</span><span class="binary">whoami</span><span class="operator">)</span> <span class="operator">(</span><span class="function">hostname</span> <span class="redirect">|</span> <span class="binary">cut</span> <span class="argument">-d</span> <span class="argument">.</span> <span class="argument">-f</span> <span class="argument">1</span><span class="operator">)</span> <span>\</span> 
            <span class="operator">(</span><span class="command">set_color</span> <span class="variable"><span class="operator">$</span>fish_color_cwd</span><span class="operator">)</span> <span class="operator">(</span><span class="command">prompt_pwd</span><span class="operator">)</span> <span class="operator">(</span><span class="command">set_color</span> <span class="argument">normal</span><span class="operator">)</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_realpath"></a>
fish_realpath - Convert a path to an absolute path without symlinks</h1>
<h2><a class="anchor" id="fish_realpath-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">fish_realpath</span> <span class="argument">path</span>
</pre><h2><a class="anchor" id="fish_realpath-description"></a>
Description</h2>
<p>This is an implementation of the external realpath command that doesn't support any options. It's meant to be used only by scripts which need to be portable. In general scripts shouldn't invoke this directly. They should just use <code>realpath</code> which will fallback to this builtin if an external command cannot be found.</p>
<p>If the path is invalid no translated path will be written to stdout and an error will be reported. This implementation behaves like the GNU command being invoked with <code>--canonicalize-existing</code>.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_right_prompt"></a>
fish_right_prompt - define the appearance of the right-side command line prompt</h1>
<h2><a class="anchor" id="fish_right_prompt-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">function</span> <span class="argument">fish_right_prompt</span>
    <span class="argument">...</span>
<span class="command">end</span>
</pre><h2><a class="anchor" id="fish_right_prompt-description"></a>
Description</h2>
<p><code>fish_right_prompt</code> is similar to <code>fish_prompt</code>, except that it appears on the right side of the terminal window.</p>
<p>Multiple lines are not supported in <code>fish_right_prompt</code>.</p>
<h2><a class="anchor" id="fish_right_prompt-example"></a>
Example</h2>
<p>A simple right prompt:</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">fish_right_prompt</span> <span class="argument">-d</span> <span class="string">"Write out the right prompt"</span>
    <span class="binary">date</span> <span class="string">'+<span>%</span>m/<span>%</span>d/<span>%</span>y'</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish"></a>
fish - the friendly interactive shell</h1>
<h2><a class="anchor" id="fish-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">fish</span> <span class="argument">[OPTIONS]</span> <span class="argument">[</span><span class="argument">-c</span> <span class="argument">command]</span> <span class="argument">[FILE</span> <span class="argument">[ARGUMENTS...]]</span>
</pre><h2><a class="anchor" id="fish-description"></a>
Description</h2>
<p><code>fish</code> is a command-line shell written mainly with interactive use in mind. The full manual is available <a href="index.html">in HTML</a> by using the <a href="#help">help</a> command from inside fish.</p>
<p>The following options are available:</p>
<ul>
<li><code>-c</code> or <code>--command=COMMANDS</code> evaluate the specified commands instead of reading from the commandline</li>
<li><code>-d</code> or <code>--debug-level=DEBUG_LEVEL</code> specify the verbosity level of fish. A higher number means higher verbosity. The default level is 1.</li>
<li><code>-i</code> or <code>--interactive</code> specify that fish is to run in interactive mode</li>
<li><code>-l</code> or <code>--login</code> specify that fish is to run as a login shell</li>
<li><code>-n</code> or <code>--no-execute</code> do not execute any commands, only perform syntax checking</li>
<li><code>-p</code> or <code>--profile=PROFILE_FILE</code> when fish exits, output timing information on all executed commands to the specified file</li>
<li><code>-v</code> or <code>--version</code> display version and exit</li>
</ul>
<p>The fish exit status is generally the exit status of the last foreground command. If fish is exiting because of a parse error, the exit status is 127.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_update_completions"></a>
fish_update_completions - Update completions using manual pages</h1>
<h2><a class="anchor" id="fish_update_completions-description"></a>
Description</h2>
<p><code>fish_update_completions</code> parses manual pages installed on the system, and attempts to create completion files in the <code>fish</code> configuration directory.</p>
<p>This does not overwrite custom completions.</p>
<p>There are no parameters for <code>fish_update_completions</code>.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="fish_vi_mode"></a>
fish_vi_mode - Enable vi mode</h1>
<h2><a class="anchor" id="fish_vi_mode-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">fish_vi_mode</span>
</pre><h2><a class="anchor" id="fish_vi_mode-description"></a>
Description</h2>
<p><code>fish_vi_mode</code> enters a vi-like command editing mode. To always start in vi mode, add <code>fish_vi_mode</code> to your <code>config.fish</code> file.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="for"></a>
for - perform a set of commands multiple times.</h1>
<h2><a class="anchor" id="for-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">for</span> <span class="argument">VARNAME</span> <span class="command">in</span> <span class="argument">[VALUES...]</span><span class="redirect">;</span> <span class="argument">COMMANDS...</span><span class="redirect">;</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="for-description"></a>
Description</h2>
<p><code>for</code> is a loop construct. It will perform the commands specified by <code>COMMANDS</code> multiple times. On each iteration, the local variable specified by <code>VARNAME</code> is assigned a new value from <code>VALUES</code>. If <code>VALUES</code> is empty, <code>COMMANDS</code> will not be executed at all.</p>
<h2><a class="anchor" id="for-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">for</span> <span class="argument">i</span> <span class="command">in</span> <span class="argument">foo</span> <span class="argument">bar</span> <span class="argument">baz</span><span class="redirect">;</span> <span class="command">echo</span> <span class="variable"><span class="operator">$</span>i</span><span class="redirect">;</span> <span class="command">end</span>

<span class="comment"># would output:</span>
<span class="argument">foo</span>
<span class="argument">bar</span>
<span class="argument">baz</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="funced"></a>
funced - edit a function interactively</h1>
<h2><a class="anchor" id="funced-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">funced</span> <span class="argument">[OPTIONS]</span> <span class="argument">NAME</span>
</pre><h2><a class="anchor" id="funced-description"></a>
Description</h2>
<p><code>funced</code> provides an interface to edit the definition of the function <code>NAME</code>.</p>
<p>If the <code>$VISUAL</code> environment variable is set, it will be used as the program to edit the function. If <code>$VISUAL</code> is unset but <code>$EDITOR</code> is set, that will be used. Otherwise, a built-in editor will be used.</p>
<p>If there is no function called <code>NAME</code> a new function will be created with the specified name</p>
<ul>
<li><code>-e command</code> or <code>--editor command</code> Open the function body inside the text editor given by the command (for example, "vi"). The command 'fish' will use the built-in editor.</li>
<li><code>-i</code> or <code>--interactive</code> Open function body in the built-in editor.</li>
</ul>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="funcsave"></a>
funcsave - save the definition of a function to the user's autoload directory</h1>
<h2><a class="anchor" id="funcsave-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">funcsave</span> <span class="argument">FUNCTION_NAME</span>
</pre><h2><a class="anchor" id="funcsave-description"></a>
Description</h2>
<p><code>funcsave</code> saves the current definition of a function to a file in the fish configuration directory. This function will be automatically loaded by current and future fish sessions. This can be useful if you have interactively created a new function and wish to save it for later use.</p>
<p>Note that because fish loads functions on-demand, saved functions will not function as <a href="index.html#event">event handlers</a> until they are run or sourced otherwise. To activate an event handler for every new shell, add the function to your <a href="index.html#initialization">shell initialization file</a> instead of using <code>funcsave</code>.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="functions"></a>
functions - print or erase functions</h1>
<h2><a class="anchor" id="functions-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">functions</span> <span class="argument">[</span> <span class="argument">-a</span> <span class="redirect">|</span> <span class="argument">--all</span> <span class="argument">]</span> <span class="argument">[</span> <span class="argument">-n</span> <span class="redirect">|</span> <span class="argument">--names</span> <span class="argument">]</span>
<span class="command">functions</span> <span class="argument">-c</span> <span class="argument">OLDNAME</span> <span class="argument">NEWNAME</span>
<span class="command">functions</span> <span class="argument">-d</span> <span class="argument">DESCRIPTION</span> <span class="argument">FUNCTION</span>
<span class="command">functions</span> <span class="argument">[</span> <span class="argument">-e</span> <span class="redirect">|</span> <span class="argument">-q</span> <span class="argument">]</span> <span class="argument">FUNCTIONS...</span>
</pre><h2><a class="anchor" id="functions-description"></a>
Description</h2>
<p><code>functions</code> prints or erases functions.</p>
<p>The following options are available:</p>
<ul>
<li><code>-a</code> or <code>--all</code> lists all functions, even those whose name start with an underscore.</li>
<li><code>-c OLDNAME NEWNAME</code> or <code>--copy OLDNAME NEWNAME</code> creates a new function named NEWNAME, using the definition of the OLDNAME function.</li>
<li><code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> changes the description of this function.</li>
<li><code>-e</code> or <code>--erase</code> causes the specified functions to be erased.</li>
<li><code>-n</code> or <code>--names</code> lists the names of all defined functions.</li>
<li><code>-q</code> or <code>--query</code> tests if the specified functions exist.</li>
</ul>
<p>The default behavior of <code>functions</code>, when called with no arguments, is to print the names of all defined functions. Unless the <code>-a</code> option is given, no functions starting with underscores are not included in the output.</p>
<p>If any non-option parameters are given, the definition of the specified functions are printed.</p>
<p>Automatically loaded functions cannot be removed using <code>functions -e</code>. Either remove the definition file or change the $fish_function_path variable to remove autoloaded functions.</p>
<p>Copying a function using <code>-c</code> copies only the body of the function, and does not attach any event notifications from the original function.</p>
<p>Only one function's description can be changed in a single invocation of <code>functions -d</code>.</p>
<p>The exit status of <code>functions</code> is the number of functions specified in the argument list that do not exist, which can be used in concert with the <code>-q</code> option.</p>
<h2><a class="anchor" id="functions-example"></a>
Examples</h2>
 
 <pre class="fish">
<span class="command">functions</span> <span class="argument">-n</span>
<span class="comment"># Displays a list of currently-defined functions</span>

<span class="command">functions</span> <span class="argument">-c</span> <span class="argument">foo</span> <span class="argument">bar</span>
<span class="comment"># Copies the 'foo' function to a new function called 'bar'</span>

<span class="command">functions</span> <span class="argument">-e</span> <span class="argument">bar</span>
<span class="comment"># Erases the function `bar`</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="function"></a>
function - create a function</h1>
<h2><a class="anchor" id="function-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">function</span> <span class="argument">NAME</span> <span class="argument">[OPTIONS]</span><span class="redirect">;</span> <span class="argument">BODY</span><span class="redirect">;</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="function-description"></a>
Description</h2>
<p><code>function</code> creates a new function <code>NAME</code> with the body <code>BODY</code>.</p>
<p>A function is a list of commands that will be executed when the name of the function is given as a command.</p>
<p>The following options are available:</p>
<ul>
<li><code>-a NAMES</code> or <code>--argument-names NAMES</code> assigns the value of successive command-line arguments to the names given in NAMES.</li>
<li><code>-d DESCRIPTION</code> or <code>--description=DESCRIPTION</code> is a description of what the function does, suitable as a completion description.</li>
<li><code>-w WRAPPED_COMMAND</code> or <code>--wraps=WRAPPED_COMMAND</code> causes the function to inherit completions from the given wrapped command. See the documentation for <a href="#complete"><code>complete</code></a> for more information.</li>
<li><code>-e</code> or <code>--on-event EVENT_NAME</code> tells fish to run this function when the specified named event is emitted. Fish internally generates named events e.g. when showing the prompt.</li>
<li><code>-v</code> or <code>--on-variable VARIABLE_NAME</code> tells fish to run this function when the variable VARIABLE_NAME changes value.</li>
<li><code>-j PGID</code> or <code>--on-job-exit PGID</code> tells fish to run this function when the job with group ID PGID exits. Instead of PGID, the string 'caller' can be specified. This is only legal when in a command substitution, and will result in the handler being triggered by the exit of the job which created this command substitution.</li>
<li><code>-p PID</code> or <code>--on-process-exit PID</code> tells fish to run this function when the fish child process with process ID PID exits.</li>
<li><code>-s</code> or <code>--on-signal SIGSPEC</code> tells fish to run this function when the signal SIGSPEC is delivered. SIGSPEC can be a signal number, or the signal name, such as SIGHUP (or just HUP).</li>
<li><code>-S</code> or <code>--no-scope-shadowing</code> allows the function to access the variables of calling functions. Normally, any variables inside the function that have the same name as variables from the calling function are "shadowed", and their contents is independent of the calling function.</li>
<li><code>-V</code> or <code>--inherit-variable NAME</code> snapshots the value of the variable <code>NAME</code> and defines a local variable with that same name and value when the function is executed.</li>
</ul>
<p>If the user enters any additional arguments after the function, they are inserted into the environment <a href="index.html#variables-arrays">variable array</a> <code>$argv</code>. If the <code>--argument-names</code> option is provided, the arguments are also assigned to names specified in that option.</p>
<p>By using one of the event handler switches, a function can be made to run automatically at specific events. The user may generate new events using the <a href="#emit">emit</a> builtin. Fish generates the following named events:</p>
<ul>
<li><code>fish_prompt</code>, which is emitted whenever a new fish prompt is about to be displayed.</li>
<li><code>fish_command_not_found</code>, which is emitted whenever a command lookup failed.</li>
<li><p class="startli"><code>fish_preexec</code>, which is emitted right before executing an interactive command. The commandline is passed as the first parameter.</p>
<p class="startli">Note: This event will be emitted even if the command is invalid. The commandline parameter includes the entire commandline verbatim, and may potentially include newlines.</p>
</li>
<li><p class="startli"><code>fish_postexec</code>, which is emitted right after executing an interactive command. The commandline is passed as the first parameter.</p>
<p class="startli">Note: This event will be emitted even if the command is invalid. The commandline parameter includes the entire commandline verbatim, and may potentially include newlines.</p>
</li>
</ul>
<h2><a class="anchor" id="function-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">ll</span>
    <span class="binary">ls</span> <span class="argument">-l</span> <span class="variable"><span class="operator">$</span>argv</span>
<span class="command">end</span>
</pre><p>will run the <code>ls</code> command, using the <code>-l</code> option, while passing on any additional files and switches to <code>ls</code>.</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument"><span class="argument">mkdir</span></span> <span class="argument">-d</span> <span class="string">"Create a directory and set CWD"</span>
    <span class="command">command</span> <span class="binary"><span class="argument">mkdir</span></span> <span class="variable"><span class="operator">$</span>argv</span>
    <span class="command">if</span> <span class="command">test</span> <span class="variable"><span class="operator">$</span>status</span> = <span class="argument">0</span>
        <span class="command">switch</span> <span class="variable"><span class="operator">$</span>argv</span>[<span class="operator">(</span><span class="command">count</span> <span class="variable"><span class="operator">$</span>argv</span><span class="operator">)</span>]
            <span class="command">case</span> <span class="string">'-*'</span>

            <span class="command">case</span> <span class="string">'*'</span>
                <span class="command">cd</span> <span class="variable"><span class="operator">$</span>argv</span>[<span class="operator">(</span><span class="command">count</span> <span class="variable"><span class="operator">$</span>argv</span><span class="operator">)</span>]
                <span class="command">return</span>
        <span class="command">end</span>
    <span class="command">end</span>
<span class="command">end</span>
</pre><p>This will run the <code>mkdir</code> command, and if it is successful, change the current working directory to the one just created.</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">notify</span>
    <span class="command">set</span> <span class="argument">-l</span> <span class="argument">job</span> <span class="operator">(</span><span class="command">jobs</span> <span class="argument">-l</span> <span class="argument">-g</span><span class="operator">)</span>
    <span class="command">or</span> <span class="command">begin</span><span class="redirect">;</span> <span class="command">echo</span> <span class="string">"There are no jobs"</span> <span class="redirect">&gt;&amp;2</span><span class="redirect">;</span> <span class="command">return</span> <span class="argument">1</span><span class="redirect">;</span> <span class="command">end</span>

    <span class="command">function</span> _notify_job_<span class="variable"><span class="operator">$</span>job</span> <span class="argument">--on-job-exit</span> <span class="variable"><span class="operator">$</span>job</span> <span class="argument">--inherit-variable</span> <span class="argument">job</span>
        <span class="command">echo</span> <span class="argument">-n</span> <span class="argument"><span>\</span>a</span> <span class="comment">## beep</span>
        <span class="command">functions</span> <span class="argument">-e</span> _notify_job_<span class="variable"><span class="operator">$</span>job</span>
    <span class="command">end</span>
<span class="command">end</span>
</pre><p>This will beep when the most recent job completes.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="help"></a>
help - display fish documentation</h1>
<h2><a class="anchor" id="help-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">help</span> <span class="argument">[SECTION]</span>
</pre><h2><a class="anchor" id="help-description"></a>
Description</h2>
<p><code>help</code> displays the fish help documentation.</p>
<p>If a <code>SECTION</code> is specified, the help for that command is shown.</p>
<p>If the BROWSER environment variable is set, it will be used to display the documentation. Otherwise, fish will search for a suitable browser.</p>
<p>Note that most builtin commands display their help in the terminal when given the <code>--help</code> option.</p>
<h2><a class="anchor" id="help-example"></a>
Example</h2>
<p><code>help fg</code> shows the documentation for the <code>fg</code> builtin.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="history"></a>
history - Show and manipulate command history</h1>
<h2><a class="anchor" id="history-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">history</span> <span class="operator">(</span> <span class="argument">--merge</span> <span class="redirect">|</span> <span class="argument">--save</span> <span class="redirect">|</span> <span class="argument">--clear</span> <span class="operator">)</span>
<span class="command">history</span> <span class="operator">(</span> <span class="argument">--search</span> <span class="redirect">|</span> <span class="argument">--delete</span> <span class="operator">)</span> <span class="argument">[</span> <span class="argument">--prefix</span> <span class="string">"prefix string"</span> <span class="redirect">|</span> <span class="argument">--contains</span> <span class="string">"search string"</span> <span class="argument">]</span>
</pre><h2><a class="anchor" id="history-description"></a>
Description</h2>
<p><code>history</code> is used to list, search and delete the history of commands used.</p>
<p>The following options are available:</p><ul>
<li><code>--merge</code> immediately incorporates history changes from other sessions. Ordinarily <code>fish</code> ignores history changes from sessions started after the current one. This command applies those changes immediately.</li>
<li><code>--save</code> saves all changes in the history file. The shell automatically saves the history file; this option is provided for internal use.</li>
<li><code>--clear</code> clears the history file. A prompt is displayed before the history is erased.</li>
<li><code>--search</code> returns history items in keeping with the <code>--prefix</code> or <code>--contains</code> options. Without either, <code>--contains</code> will be assumed.</li>
<li><code>--delete</code> deletes history items. Without the <code>--prefix</code> or <code>--contains</code> options, the exact match will be deleted. With either of these options, a prompt will be displayed before any items are deleted.</li>
<li><code>--prefix</code> searches or deletes items in the history that begin with the specified text string.</li>
<li><code>--contains</code> searches or deletes items in the history that contain the specified text string.</li>
</ul>
<h2><a class="anchor" id="history-examples"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">history</span> <span class="argument">--clear</span>
<span class="comment"># Deletes all history items</span>

<span class="command">history</span> <span class="argument">--search</span> <span class="argument">--</span><span class="argument">contains</span> <span class="string">"foo"</span>
<span class="comment"># Outputs a list of all previous commands containing the string "foo".</span>

<span class="command">history</span> <span class="argument">--delete</span> <span class="argument">--prefix</span> <span class="string">"foo"</span>
<span class="comment"># Interactively deletes the record of previous commands which start with "foo".</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="if"></a>
if - conditionally execute a command</h1>
<h2><a class="anchor" id="if-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">if</span> <span class="argument">CONDITION</span><span class="redirect">;</span> <span class="argument">COMMANDS_TRUE...</span><span class="redirect">;</span>
<span class="argument">[<span class="command">else</span> <span class="command">if</span> <span class="argument">CONDITION2</span><span class="redirect">;</span> <span class="argument">COMMANDS_TRUE2...</span>;]</span>
<span class="argument">[<span class="command">else</span><span class="redirect">;</span> <span class="argument">COMMANDS_FALSE...</span>;]</span>
<span class="command">end</span>
</pre><h2><a class="anchor" id="if-description"></a>
Description</h2>
<p><code>if</code> will execute the command <code>CONDITION</code>. If the condition's exit status is 0, the commands <code>COMMANDS_TRUE</code> will execute. If the exit status is not 0 and <code>else</code> is given, <code>COMMANDS_FALSE</code> will be executed.</p>
<p>You can use <a href="#and"><code>and</code></a> or <a href="#and"><code>or</code></a> in the condition. See the second example below.</p>
<p>The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.</p>
<h2><a class="anchor" id="if-example"></a>
Example</h2>
<p>The following code will print <code>foo.txt exists</code> if the file foo.txt exists and is a regular file, otherwise it will print <code>bar.txt exists</code> if the file bar.txt exists and is a regular file, otherwise it will print <code>foo.txt and bar.txt do not exist</code>.</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="argument">-f</span> <span class="file">foo.txt</span>
    <span class="command">echo</span> <span class="argument">foo.txt</span> <span class="argument">exists</span>
<span class="command">else</span> <span class="command">if</span> <span class="command">test</span> <span class="argument">-f</span> <span class="file">bar.txt</span>
    <span class="command">echo</span> <span class="argument">bar.txt</span> <span class="argument">exists</span>
<span class="command">else</span>
    <span class="command">echo</span> <span class="argument">foo.txt</span> <span class="argument">and</span> <span class="argument">bar.txt</span> <span class="argument">do</span> <span class="argument">not</span> <span class="argument">exist</span>
<span class="command">end</span>
</pre><p>The following code will print "foo.txt exists and is readable" if foo.txt is a regular file and readable </p> 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="argument">-f</span> <span class="file">foo.txt</span>
   <span class="command">and</span> <span class="command">test</span> <span class="argument">-r</span> <span class="file">foo.txt</span>
   <span class="command">echo</span> <span class="string">"foo.txt exists and is readable"</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="isatty"></a>
isatty - test if a file descriptor is a tty.</h1>
<h2><a class="anchor" id="isatty-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">isatty</span> <span class="argument">[FILE <span class="argument">DESCRIPTOR]</span></span>
</pre><h2><a class="anchor" id="isatty-description"></a>
Description</h2>
<p><code>isatty</code> tests if a file descriptor is a tty.</p>
<p><code>FILE DESCRIPTOR</code> may be either the number of a file descriptor, or one of the strings <code>stdin</code>, <code>stdout</code>, or <code>stderr</code>.</p>
<p>If the specified file descriptor is a tty, the exit status of the command is zero. Otherwise, the exit status is non-zero. No messages are printed to standard error.</p>
<h2><a class="anchor" id="isatty-examples"></a>
Examples</h2>
<p>From an interactive shell, the commands below exit with a return value of zero:</p>
 
 <pre class="fish">
<span class="command">isatty</span>
<span class="command">isatty</span> <span class="argument">stdout</span>
<span class="command">isatty</span> <span class="argument">2</span>
<span class="command">echo</span> <span class="redirect">|</span> <span class="command">isatty</span> <span class="argument">1</span>
</pre><p>And these will exit non-zero:</p>
 
 <pre class="fish">
<span class="command">echo</span> <span class="redirect">|</span> <span class="command">isatty</span>
<span class="command">isatty</span> <span class="argument">9</span>
<span class="command">isatty</span> <span class="argument">stdout</span> <span class="redirect">&gt; file</span>
<span class="command">isatty</span> <span class="argument">2</span> <span class="redirect">2&gt; file</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="jobs"></a>
jobs - print currently running jobs</h1>
<h2><a class="anchor" id="jobs-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">jobs</span> <span class="argument">[OPTIONS]</span> <span class="argument">[PID]</span>
</pre><h2><a class="anchor" id="jobs-description"></a>
Description</h2>
<p><code>jobs</code> prints a list of the currently running <a href="index.html#syntax-job-control">jobs</a> and their status.</p>
<p>jobs accepts the following switches:</p>
<ul>
<li><code>-c</code> or <code>--command</code> prints the command name for each process in jobs.</li>
<li><code>-g</code> or <code>--group</code> only prints the group ID of each job.</li>
<li><code>-l</code> or <code>--last</code> prints only the last job to be started.</li>
<li><code>-p</code> or <code>--pid</code> prints the process ID for each process in all jobs.</li>
</ul>
<p>On systems that supports this feature, jobs will print the CPU usage of each job since the last command was executed. The CPU usage is expressed as a percentage of full CPU activity. Note that on multiprocessor systems, the total activity may be more than 100%.</p>
<h2><a class="anchor" id="jobs-example"></a>
Example</h2>
<p><code>jobs</code> outputs a summary of the current jobs.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
<h1><a class="anchor" id="math"></a>
math - Perform mathematics calculations</h1>
<h2><a class="anchor" id="math-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">math</span> <span class="argument">EXPRESSION</span>
</pre><h2><a class="anchor" id="math-description"></a>
Description</h2>
<p><code>math</code> is used to perform mathematical calculations. It is a very thin wrapper for the bc program, which makes it possible to specify an expression from the command line without using non-standard extensions or a pipeline.</p>
<p>For a description of the syntax supported by math, see the manual for the bc program. Keep in mind that parameter expansion takes place on any expressions before they are evaluated. This can be very useful in order to perform calculations involving shell variables or the output of command substitutions, but it also means that parenthesis have to be escaped.</p>
<h2><a class="anchor" id="math-example"></a>
Examples</h2>
<p><code>math 1+1</code> outputs 2.</p>
<p><code>math $status-128</code> outputs the numerical exit status of the last command minus 128.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="nextd"></a>
nextd - move forward through directory history</h1>
<h2><a class="anchor" id="nextd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">nextd</span> <span class="argument">[</span> <span class="argument">-l</span> <span class="redirect">|</span> <span class="argument">--list</span> <span class="argument">]</span> <span class="argument">[POS]</span>
</pre><h2><a class="anchor" id="nextd-description"></a>
Description</h2>
<p><code>nextd</code> moves forwards <code>POS</code> positions in the history of visited directories; if the end of the history has been hit, a warning is printed.</p>
<p>If the <code>-l</code> or <code>--list</code> flag is specified, the current directory history is also displayed.</p>
<p>Note that the <code>cd</code> command limits directory history to the 25 most recently visited directories. The history is stored in the <code>$dirprev</code> and <code>$dirnext</code> variables which this command manipulates.</p>
<h2><a class="anchor" id="nextd-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">cd</span> <span class="path">/usr/src</span>
<span class="comment"># Working directory is now /usr/src</span>

<span class="command">cd</span> <span class="path">/usr/src/fish-shell</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>

<span class="command">prevd</span>
<span class="comment"># Working directory is now /usr/src</span>

<span class="command">nextd</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="not"></a>
not - negate the exit status of a job</h1>
<h2><a class="anchor" id="not-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">not</span> <span class="argument">COMMAND</span> <span class="argument">[OPTIONS...]</span>
</pre><h2><a class="anchor" id="not-description"></a>
Description</h2>
<p><code>not</code> negates the exit status of another command. If the exit status is zero, <code>not</code> returns 1. Otherwise, <code>not</code> returns 0.</p>
<h2><a class="anchor" id="not-example"></a>
Example</h2>
<p>The following code reports an error and exits if no file named spoon can be found.</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">not</span> <span class="command">test</span> <span class="argument">-f</span> <span class="argument">spoon</span>
    <span class="command">echo</span> <span class="argument">There</span> <span class="argument">is</span> <span class="argument">no</span> <span class="argument">spoon</span>
    <span class="command">exit</span> <span class="argument">1</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="open"></a>
open - open file in its default application</h1>
<h2><a class="anchor" id="open-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">open</span> <span class="argument">FILES...</span>
</pre><h2><a class="anchor" id="open-description"></a>
Description</h2>
<p><code>open</code> opens a file in its default application, using the appropriate tool for the operating system. On GNU/Linux, this requires the common but optional <code>xdg-open</code> utility, from the <code>xdg-utils</code> package.</p>
<h2><a class="anchor" id="open-example"></a>
Example</h2>
<p><code>open *.txt</code> opens all the text files in the current directory using your system's default text editor.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="or"></a>
or - conditionally execute a command</h1>
<h2><a class="anchor" id="or-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="argument">COMMAND1</span><span class="redirect">;</span> <span class="command">or</span> <span class="argument">COMMAND2</span>
</pre><h2><a class="anchor" id="or-description"></a>
Description</h2>
<p><code>or</code> is used to execute a command if the current exit status (as set by the previous command) is not 0.</p>
<p><code>or</code> statements may be used as part of the condition in an <a href="#if"><code>and</code></a> or <a href="#while"><code>while</code></a> block. See the documentation for <a href="#if"><code>if</code></a> and <a href="#while"><code>while</code></a> for examples.</p>
<p><code>or</code> does not change the current exit status. The exit status of the last foreground command to exit can always be accessed using the <a href="index.html#variables-status">$status</a> variable.</p>
<h2><a class="anchor" id="or-example"></a>
Example</h2>
<p>The following code runs the <code>make</code> command to build a program. If the build succeeds, the program is installed. If either step fails, <code>make clean</code> is run, which removes the files created by the build process.</p>
 
 <pre class="fish">
<span class="binary">make</span><span class="redirect">;</span> <span class="command">and</span> <span class="binary">make</span> <span class="argument">install</span><span class="redirect">;</span> <span class="command">or</span> <span class="binary">make</span> <span class="argument">clean</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="popd"></a>
popd - move through directory stack</h1>
<h2><a class="anchor" id="popd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">popd</span>
</pre><h2><a class="anchor" id="popd-description"></a>
Description</h2>
<p><code>popd</code> removes the top directory from the directory stack and changes the working directory to the new top directory. Use <a href="#pushd"><code>pushd</code></a> to add directories to the stack.</p>
<h2><a class="anchor" id="popd-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">pushd</span> <span class="path">/usr/src</span>
<span class="comment"># Working directory is now /usr/src</span>
<span class="comment"># Directory stack contains /usr/src</span>

<span class="command">pushd</span> <span class="path">/usr/src/fish-shell</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>
<span class="comment"># Directory stack contains /usr/src /usr/src/fish-shell</span>

<span class="command">popd</span>
<span class="comment"># Working directory is now /usr/src</span>
<span class="comment"># Directory stack contains /usr/src</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="prevd"></a>
prevd - move backward through directory history</h1>
<h2><a class="anchor" id="prevd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">prevd</span> <span class="argument">[</span> <span class="argument">-l</span> <span class="redirect">|</span> <span class="argument">--list</span> <span class="argument">]</span> <span class="argument">[POS]</span>
</pre><h2><a class="anchor" id="prevd-description"></a>
Description</h2>
<p><code>prevd</code> moves backwards <code>POS</code> positions in the history of visited directories; if the beginning of the history has been hit, a warning is printed.</p>
<p>If the <code>-l</code> or <code>--list</code> flag is specified, the current history is also displayed.</p>
<p>Note that the <code>cd</code> command limits directory history to the 25 most recently visited directories. The history is stored in the <code>$dirprev</code> and <code>$dirnext</code> variables which this command manipulates.</p>
<h2><a class="anchor" id="prevd-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">cd</span> <span class="path">/usr/src</span>
<span class="comment"># Working directory is now /usr/src</span>

<span class="command">cd</span> <span class="path">/usr/src/fish-shell</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>

<span class="command">prevd</span>
<span class="comment"># Working directory is now /usr/src</span>

<span class="command">nextd</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="printf"></a>
printf - display text according to a format string</h1>
<h2><a class="anchor" id="printf-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">printf</span> <span class="argument">format</span> <span class="argument">[argument...]</span>
</pre><h2><a class="anchor" id="printf-description"></a>
Description</h2>
<p>printf formats the string FORMAT with ARGUMENT, and displays the result.</p>
<p>The string FORMAT should contain format specifiers, each of which are replaced with successive arguments according to the specifier. Specifiers are detailed below, and are taken from the C library function <code>printf(3)</code>.</p>
<p>Unlike <code>echo</code>, <code>printf</code> does not append a new line unless it is specified as part of the string.</p>
<p>Valid format specifiers are:</p>
<ul>
<li><code>%d</code>: Argument will be used as decimal integer (signed or unsigned)</li>
<li><code>%i</code>: Argument will be used as a signed integer</li>
<li><code>%o</code>: An octal unsigned integer</li>
<li><code>%u</code>: An unsigned decimal integer</li>
<li><code>%x</code> or <code>%X</code>: An unsigned hexadecimal integer</li>
<li><code>%f</code>, <code>%g</code> or <code>%G</code>: A floating-point number</li>
<li><code>%e</code> or <code>%E</code>: A floating-point number in scientific (XXXeYY) notation</li>
<li><code>%s</code>: A string</li>
<li><code>%b</code>: As a string, interpreting backslash escapes, except that octal escapes are of the form \0 or \0ooo.</li>
</ul>
<p><code>%%</code> signifies a literal "%".</p>
<p>Note that conversion may fail, e.g. "102.234" will not losslessly convert to an integer, causing printf to print an error.</p>
<p>printf also knows a number of backslash escapes:</p><ul>
<li><code>\"</code> double quote</li>
<li><code>\\</code> backslash</li>
<li><code>\a</code> alert (bell)</li>
<li><code>\b</code> backspace</li>
<li><code>\c</code> produce no further output</li>
<li><code>\e</code> escape</li>
<li><code>\f</code> form feed</li>
<li><code>\n</code> new line</li>
<li><code>\r</code> carriage return</li>
<li><code>\t</code> horizontal tab</li>
<li><code>\v</code> vertical tab</li>
<li><code>\ooo</code> octal number (ooo is 1 to 3 digits)</li>
<li><code>\xhh</code> hexadecimal number (hhh is 1 to 2 digits)</li>
<li><code>\uhhhh</code> 16-bit Unicode character (hhhh is 4 digits)</li>
<li><code>\Uhhhhhhhh</code> 32-bit Unicode character (hhhhhhhh is 8 digits)</li>
</ul>
<p>The `format' argument is re-used as many times as necessary to convert all of the given arguments. If a format specifier is not appropriate for the given argument, an error is printed. For example, `printf 'd' "102.234"` produces an error, as "102.234" cannot be formatted as an integer.</p>
<p>This file has been imported from the printf in GNU Coreutils version 6.9. If you would like to use a newer version of printf, for example the one shipped with your OS, try <code>command printf</code>.</p>
<h2><a class="anchor" id="printf-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">printf</span> <span class="string">'<span>%</span>s<span>\</span>t<span>%</span>s<span>\</span>n'</span> <span class="argument">flounder</span> <span class="argument">fish</span>
</pre><p>Will print "flounder    fish" (separated with a tab character), followed by a newline character. This is useful for writing completions, as fish expects completion scripts to output the option followed by the description, separated with a tab character.</p>
 
 <pre class="fish">
<span class="command">printf</span> <span class="string">'<span>%</span>s:<span>%</span>d'</span> <span class="string">"Number of bananas in my pocket"</span> <span class="argument">42</span>
</pre><p>Will print "Number of bananas in my pocket: 42", <em>without</em> a newline.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="prompt_pwd"></a>
prompt_pwd - Print pwd suitable for prompt</h1>
<h2><a class="anchor" id="prompt_pwd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">prompt_pwd</span>
</pre><h2><a class="anchor" id="prompt_pwd-description"></a>
Description</h2>
<p>prompt_pwd is a function to print the current working directory in a way suitable for prompts. It will replace the home directory with "~" and shorten every path component but the last to a default of one character.</p>
<p>To change the number of characters per path component, set $fish_prompt_pwd_dir_length to the number of characters. Setting it to 0 or an invalid value will disable shortening entirely.</p>
<h2><a class="anchor" id="prompt_pwd-example"></a>
Examples</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">cd</span> <span class="path">~/</span>
<span class="prompt">&gt;</span> <span class="command">echo</span> <span class="variable"><span class="operator">$</span>PWD</span>
<span class="output">/home/alfa</span>

<span class="prompt">&gt;</span> <span class="command">prompt_pwd</span>
<span class="output">~</span>

<span class="prompt">&gt;</span> <span class="command">cd</span> <span class="path">/tmp/banana/sausage/with/mustard</span>
<span class="prompt">&gt;</span> <span class="command">prompt_pwd</span>
<span class="output">/t/b/s/w/mustard</span>

<span class="prompt">&gt;</span> <span class="command">set</span> <span class="argument">-g</span> <span class="argument">fish_prompt_pwd_dir_length</span> <span class="argument">3</span>
<span class="prompt">&gt;</span> <span class="command">prompt_pwd</span>
<span class="output">/tmp/ban/sau/wit/mustard</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="psub"></a>
psub - perform process substitution</h1>
<h2><a class="anchor" id="psub-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="argument">COMMAND1</span> <span class="operator">(</span> <span class="argument">COMMAND2</span> <span class="redirect">|</span> <span class="command">psub</span> <span class="argument">[</span><span class="argument">-f</span>] <span class="argument">[</span><span class="argument">-s</span> <span class="argument">SUFFIX]</span><span class="operator">)</span>
</pre><h2><a class="anchor" id="psub-description"></a>
Description</h2>
<p>Posix shells feature a syntax that is a mix between command substitution and piping, called process substitution. It is used to send the output of a command into the calling command, much like command substitution, but with the difference that the output is not sent through commandline arguments but through a named pipe, with the filename of the named pipe sent as an argument to the calling program. <code>psub</code> combined with a regular command substitution provides the same functionality.</p>
<p>If the <code>-f</code> or <code>--file</code> switch is given to <code>psub</code>, <code>psub</code> will use a regular file instead of a named pipe to communicate with the calling process. This will cause <code>psub</code> to be significantly slower when large amounts of data are involved, but has the advantage that the reading process can seek in the stream.</p>
<p>If the <code>-s</code> or <code>---suffix</code> switch is given, <code>psub</code> will append SUFFIX to the filename.</p>
<h2><a class="anchor" id="psub-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="binary">diff</span> <span class="operator">(</span><span class="binary">sort</span> <span class="file">a.txt</span> <span class="redirect">|</span> <span class="command">psub</span><span class="operator">)</span> <span class="operator">(</span><span class="binary">sort</span> <span class="file">b.txt</span> <span class="redirect">|</span> <span class="command">psub</span><span class="operator">)</span>
<span class="comment"># shows the difference between the sorted versions of files `a.txt` and `b.txt`.</span>

<span class="command">source</span>-<span class="argument">highlight</span> <span class="argument">-f</span> <span class="argument">esc</span> <span class="operator">(</span>cpp <span class="file">main.c</span> <span class="redirect">|</span> <span class="command">psub</span> <span class="argument">-s</span> <span class="argument">.c</span><span class="operator">)</span>
<span class="comment"># highlights `main.c` after preprocessing as a C source.</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="pushd"></a>
pushd - push directory to directory stack</h1>
<h2><a class="anchor" id="pushd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">pushd</span> <span class="argument">[DIRECTORY]</span>
</pre><h2><a class="anchor" id="pushd-description"></a>
Description</h2>
<p>The <code>pushd</code> function adds <code>DIRECTORY</code> to the top of the directory stack and makes it the current working directory. <a href="#popd"><code>popd</code></a> will pop it off and return to the original directory.</p>
<p>Without arguments, it exchanges the top two directories in the stack.</p>
<p><code>pushd +NUMBER</code> rotates the stack counter-clockwise i.e. from bottom to top</p>
<p><code>pushd -NUMBER</code> rotates clockwise i.e. top to bottom.</p>
<p>See also <code>dirs</code> and <code>dirs -c</code>.</p>
<h2><a class="anchor" id="pushd-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">pushd</span> <span class="path">/usr/src</span>
<span class="comment"># Working directory is now /usr/src</span>
<span class="comment"># Directory stack contains /usr/src</span>

<span class="command">pushd</span> <span class="path">/usr/src/fish-shell</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>
<span class="comment"># Directory stack contains /usr/src /usr/src/fish-shell</span>

<span class="command">pushd</span> <span class="path">/tmp/</span>
<span class="comment"># Working directory is now /tmp</span>
<span class="comment"># Directory stack contains /tmp /usr/src /usr/src/fish-shell</span>

<span class="command">pushd</span> <span class="argument">+1</span>
<span class="comment"># Working directory is now /usr/src</span>
<span class="comment"># Directory stack contains /usr/src /usr/src/fish-shell /tmp</span>

<span class="command">popd</span>
<span class="comment"># Working directory is now /usr/src/fish-shell</span>
<span class="comment"># Directory stack contains /usr/src/fish-shell /tmp</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="pwd"></a>
pwd - output the current working directory</h1>
<h2><a class="anchor" id="pwd-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">pwd</span>
</pre><h2><a class="anchor" id="pwd-description"></a>
Description</h2>
<p><code>pwd</code> outputs (prints) the current working directory.</p>
<p>Note that <code>fish</code> always resolves symbolic links in the current directory path.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="random"></a>
random - generate random number</h1>
<h2><a class="anchor" id="random-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">random</span> <span class="argument">[SEED]</span>
</pre><h2><a class="anchor" id="random-description"></a>
Description</h2>
<p><code>random</code> outputs a psuedo-random number from 0 to 32767, inclusive. Even ignoring the very narrow range of values you should not assume this produces truly random values within that range. Do not use the value for any cryptographic purposes, and take care to handle collisions: the same random number appearing more than once in a given fish instance.</p>
<p>If a <code>SEED</code> value is provided, it is used to seed the random number generator, and no output will be produced. This can be useful for debugging purposes, where it can be desirable to get the same random number sequence multiple times. If the random number generator is called without first seeding it, the current time will be used as the seed.</p>
<h2><a class="anchor" id="random-example"></a>
Example</h2>
<p>The following code will count down from a random number to 1:</p>
 
 <pre class="fish">
<span class="command">for</span> <span class="argument">i</span> <span class="command">in</span> <span class="operator">(</span><span class="binary">seq</span> <span class="operator">(</span><span class="command">random</span><span class="operator">)</span> <span class="argument">-1</span> <span class="argument">1</span><span class="operator">)</span>
    <span class="command">echo</span> <span class="variable"><span class="operator">$</span>i</span>
    <span class="command">sleep</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="read"></a>
read - read line of input into variables</h1>
<h2><a class="anchor" id="read-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">read</span> <span class="argument">[OPTIONS]</span> <span class="argument">[VARIABLES...]</span>
</pre><h2><a class="anchor" id="read-description"></a>
Description</h2>
<p><code>read</code> reads one line from standard input and stores the result in one or more shell variables.</p>
<p>The following options are available:</p>
<ul>
<li><code>-c CMD</code> or <code>--command=CMD</code> sets the initial string in the interactive mode command buffer to <code>CMD</code>.</li>
<li><code>-g</code> or <code>--global</code> makes the variables global.</li>
<li><code>-l</code> or <code>--local</code> makes the variables local.</li>
<li><code>-m NAME</code> or <code>--mode-name=NAME</code> specifies that the name NAME should be used to save/load the history file. If NAME is fish, the regular fish history will be available.</li>
<li><code>-n NCHARS</code> or <code>--nchars=NCHARS</code> causes <code>read</code> to return after reading NCHARS characters rather than waiting for a complete line of input.</li>
<li><code>-p PROMPT_CMD</code> or <code>--prompt=PROMPT_CMD</code> uses the output of the shell command <code>PROMPT_CMD</code> as the prompt for the interactive mode. The default prompt command is <code>set_color green; echo read; set_color normal; echo "&gt; "</code>.</li>
<li><code>-R RIGHT_PROMPT_CMD</code> or <code>--right-prompt=RIGHT_PROMPT_CMD</code> uses the output of the shell command <code>RIGHT_PROMPT_CMD</code> as the right prompt for the interactive mode. There is no default right prompt command.</li>
<li><code>-s</code> or <code>--shell</code> enables syntax highlighting, tab completions and command termination suitable for entering shellscript code in the interactive mode.</li>
<li><code>-u</code> or <code>--unexport</code> prevents the variables from being exported to child processes (default behaviour).</li>
<li><code>-U</code> or <code>--universal</code> causes the specified shell variable to be made universal.</li>
<li><code>-x</code> or <code>--export</code> exports the variables to child processes.</li>
<li><code>-a</code> or <code>--array</code> stores the result as an array.</li>
<li><code>-z</code> or <code>--null</code> reads up to NUL instead of newline. Disables interactive mode.</li>
</ul>
<p><code>read</code> reads a single line of input from stdin, breaks it into tokens based on the <code>IFS</code> shell variable, and then assigns one token to each variable specified in <code>VARIABLES</code>. If there are more tokens than variables, the complete remainder is assigned to the last variable. As a special case, if <code>IFS</code> is set to the empty string, each character of the input is considered a separate token.</p>
<p>If <code>-a</code> or <code>--array</code> is provided, only one variable name is allowed and the tokens are stored as an array in this variable.</p>
<p>See the documentation for <code>set</code> for more details on the scoping rules for variables.</p>
<h2><a class="anchor" id="read-example"></a>
Example</h2>
<p>The following code stores the value 'hello' in the shell variable <code>$foo</code>.</p>
 
 <pre class="fish">
<span class="command">echo</span> <span class="argument">hello</span><span class="redirect">|</span><span class="command">read</span> <span class="argument">foo</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="return"></a>
return - stop the current inner function</h1>
<h2><a class="anchor" id="return-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">function</span> <span class="argument">NAME</span><span class="redirect">;</span> <span class="argument">[COMMANDS...;]</span> <span class="command">return</span> <span class="argument">[STATUS]</span><span class="redirect">;</span> <span class="argument">[COMMANDS...;]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="return-description"></a>
Description</h2>
<p><code>return</code> halts a currently running function. The exit status is set to <code>STATUS</code> if it is given.</p>
<p>It is usually added inside of a conditional block such as an <a href="#if">if</a> statement or a <a href="#switch">switch</a> statement to conditionally stop the executing function and return to the caller, but it can also be used to specify the exit status of a function.</p>
<h2><a class="anchor" id="return-example"></a>
Example</h2>
<p>The following code is an implementation of the false command as a fish function</p>
 
 <pre class="fish">
<span class="command">function</span> <span class="argument">false</span>
    <span class="command">return</span> <span class="argument">1</span>
<span class="command">end</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="set_color"></a>
set_color - set the terminal color</h1>
<h2><a class="anchor" id="set_color-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">set_color</span> <span class="argument">[OPTIONS]</span> <span class="argument">[COLOR]</span>
</pre><h2><a class="anchor" id="set_color-description"></a>
Description</h2>
<p><code>set_color</code> changes the foreground and/or background color of the terminal. <code>COLOR</code> is one of <code>black</code>, <code>red</code>, <code>green</code>, <code>brown</code>, <code>yellow</code>, <code>blue</code>, <code>magenta</code>, <code>purple</code>, <code>cyan</code>, <code>brred</code>, <code>brgreen</code>, <code>brbrown</code>, <code>bryellow</code>, <code>brblue</code>, <code>brmagenta</code>, <code>brpurple</code>, <code>brcyan</code>, <code>white</code>. The <code>br</code>, bright, forms are most useful as background colors. The special color <code>normal</code> resets the background and foreground to whatever is normal for your terminal.</p>
<p>You can also specify an RGB value with three or six hex digits, such as A0FF33 or f2f. <code>fish</code> will choose the closest supported color. A three digit value is equivalent to specifying each digit twice; e.g., <code>#2BC</code> is the same as <code>#22BBCC</code>. Hex RGB values can be in lower or uppercase, optionally prefixed with the pound-sign character. Depending on the capabilities of your terminal the actual color may be approximated by the closest known matching color in the <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#Colors">ANSI X3.64</a> color palette.</p>
<p>The following options are available:</p>
<ul>
<li><code>-b</code>, <code>--background</code> <code>COLOR</code> sets the background color.</li>
<li><code>-c</code>, <code>--print-colors</code> prints a list of all valid color names.</li>
<li><code>-o</code>, <code>--bold</code> sets bold or extra bright mode.</li>
<li><code>-u</code>, <code>--underline</code> sets underlined mode.</li>
</ul>
<p>Calling <code>set_color normal</code> will set the terminal background and foreground colors to the defaults for the terminal.</p>
<p>Some terminals use the <code>--bold</code> escape sequence to switch to a brighter color set rather than bolding the characters. This only applies to the foreground color. You should probably use the <code>br</code> color name variants listed above for both the foreground and background "bright" colors rather than use this option. The only use for this option is on a black&amp;white terminal (e.g., a DEC VT220) to select foreground black text that is bolder than the normal text.</p>
<p>Not all terminal emulators support all these features.</p>
<p>Note 1: Setting either color to "normal" will reset both background and foreground colors to whatever is the default for the terminal.</p>
<p>Note 2: Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides.</p>
<h2><a class="anchor" id="set_color-example"></a>
Examples</h2>
 
 <pre class="fish">
<span class="command">set_color</span> <span class="argument">red</span><span class="redirect">;</span> <span class="command">echo</span> <span class="string">"Roses are red"</span>
<span class="command">set_color</span> <span class="argument">blue</span><span class="redirect">;</span> <span class="command">echo</span> <span class="string">"Violets are blue"</span>
<span class="command">set_color</span> <span class="argument">62A</span><span class="redirect">;</span> <span class="command">echo</span> <span class="string">"Eggplants are dark purple"</span>
<span class="command">set_color</span> <span class="argument">normal</span><span class="redirect">;</span> <span class="command">echo</span> <span class="string">"Normal is nice"</span> <span class="comment">## This will reset background, too</span>
</pre><h2><a class="anchor" id="set_color-detection"></a>
Terminal Capability Detection</h2>
<p>Fish uses a heuristic to decide if your terminal supports the 256 color palette (as opposed to the more limited 16 color palette of older terminals). If you've done the equivalent of <code>set fish_term256 1</code> that will be true. If the $TERM value contains "256color" (e.g., "xterm-256color") that will be true. If your $TERM value is "xterm" and $TERM_PROGRAM is not set to "Apple_Terminal" that will be true. If your terminal supports the full 256 color palette (which is pretty much every color terminal emulator written in the past decade) you should ensure one of the aforementioned conditions is true.</p>
<p>Many terminals support 24-bit (i.e., true-color) color escape sequences. This includes modern xterms, Gnome Terminal, KDE Konsole, and iTerm2. Fish currently does some limited attempts to detect whether a given <code>$TERM</code> supports 24-bit colors. You can explicitly enable that support via <code>set fish_term24bit 1</code>. If you do so fish will not map your RGB color values to the closest known matching color in the ANSI X3.64 color palette.</p>
<p>The <code>set_color</code> command uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Fish will use the <a href="https://en.wikipedia.org/wiki/ANSI_escape_code">ANSI X3.64</a> escape sequences if the terminfo definition says less than 256 colors are supported; otherwise it will use the terminfo definition.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="set"></a>
set - display and change shell variables.</h1>
<h2><a class="anchor" id="set-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">set</span> <span class="argument">[SCOPE_OPTIONS]</span>
<span class="command">set</span> <span class="argument">[OPTIONS]</span> <span class="argument">VARIABLE_NAME</span> <span class="argument">VALUES...</span>
<span class="command">set</span> <span class="argument">[OPTIONS]</span> <span class="argument">VARIABLE_NAME</span><span class="argument">[INDICES]</span>... <span class="argument">VALUES...</span>
<span class="command">set</span> <span class="operator">(</span> <span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--query</span> <span class="operator">)</span> <span class="argument">[SCOPE_OPTIONS]</span> <span class="argument">VARIABLE_NAMES...</span>
<span class="command">set</span> <span class="operator">(</span> <span class="argument">-e</span> <span class="redirect">|</span> <span class="argument">--erase</span> <span class="operator">)</span> <span class="argument">[SCOPE_OPTIONS]</span> <span class="argument">VARIABLE_NAME</span>
<span class="command">set</span> <span class="operator">(</span> <span class="argument">-e</span> <span class="redirect">|</span> <span class="argument">--erase</span> <span class="operator">)</span> <span class="argument">[SCOPE_OPTIONS]</span> <span class="argument">VARIABLE_NAME</span><span class="argument">[INDICES]</span><span class="argument">...</span>
</pre><h2><a class="anchor" id="set-description"></a>
Description</h2>
<p><code>set</code> manipulates <a href="index.html#variables">shell variables</a>.</p>
<p>If set is called with no arguments, the names and values of all shell variables are printed. If some of the scope or export flags have been given, only the variables matching the specified scope are printed.</p>
<p>With both variable names and values provided, <code>set</code> assigns the variable <code>VARIABLE_NAME</code> the values <code>VALUES...</code>.</p>
<p>The following options control variable scope:</p>
<ul>
<li><code>-l</code> or <code>--local</code> forces the specified shell variable to be given a scope that is local to the current block, even if a variable with the given name exists and is non-local</li>
<li><code>-g</code> or <code>--global</code> causes the specified shell variable to be given a global scope. Non-global variables disappear when the block they belong to ends</li>
<li><code>-U</code> or <code>--universal</code> causes the specified shell variable to be given a universal scope. If this option is supplied, the variable will be shared between all the current users fish instances on the current computer, and will be preserved across restarts of the shell.</li>
<li><code>-x</code> or <code>--export</code> causes the specified shell variable to be exported to child processes (making it an "environment variable")</li>
<li><code>-u</code> or <code>--unexport</code> causes the specified shell variable to NOT be exported to child processes</li>
</ul>
<p>The following options are available:</p>
<ul>
<li><code>-e</code> or <code>--erase</code> causes the specified shell variable to be erased</li>
<li><code>-q</code> or <code>--query</code> test if the specified variable names are defined. Does not output anything, but the builtins exit status is the number of variables specified that were not defined.</li>
<li><code>-n</code> or <code>--names</code> List only the names of all defined variables, not their value</li>
<li><code>-L</code> or <code>--long</code> do not abbreviate long values when printing set variables</li>
</ul>
<p>If a variable is set to more than one value, the variable will be an array with the specified elements. If a variable is set to zero elements, it will become an array with zero elements.</p>
<p>If the variable name is one or more array elements, such as <code>PATH[1 3 7]</code>, only those array elements specified will be changed. When array indices are specified to <code>set</code>, multiple arguments may be used to specify additional indexes, e.g. <code>set PATH[1] PATH[4] /bin /sbin</code>. If you specify a negative index when expanding or assigning to an array variable, the index will be calculated from the end of the array. For example, the index -1 means the last index of an array.</p>
<p>The scoping rules when creating or updating a variable are:</p>
<ol type="1">
<li>If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed.</li>
<li>If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the previous variable scope is used.</li>
<li>If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the <code>-l</code> or <code>--local</code> flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global.</li>
</ol>
<p>The exporting rules when creating or updating a variable are identical to the scoping rules for variables:</p>
<ol type="1">
<li>If a variable is explicitly set to either be exported or not exported, that setting will be honored.</li>
<li>If a variable is not explicitly set to be exported or not exported, but has been previously defined, the previous exporting rule for the variable is kept.</li>
<li>If a variable is not explicitly set to be either exported or unexported and has never before been defined, the variable will not be exported.</li>
</ol>
<p>In query mode, the scope to be examined can be specified.</p>
<p>In erase mode, if variable indices are specified, only the specified slices of the array variable will be erased.</p>
<p><code>set</code> requires all options to come before any other arguments. For example, <code>set flags -l</code> will have the effect of setting the value of the variable <code>flags</code> to '-l', not making the variable local.</p>
<p>In assignment mode, <code>set</code> exits with a non-zero exit status if variable assignments could not be successfully performed. If the variable assignments were performed, the exit status is unchanged. This allows simultaneous capture of the output and exit status of a subcommand, e.g. <code>if set output (command)</code>. In query mode, the exit status is the number of variables that were not found. In erase mode, <code>set</code> exits with a zero exit status in case of success, with a non-zero exit status if the commandline was invalid, if the variable was write-protected or if the variable did not exist.</p>
<h2><a class="anchor" id="set-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">set</span> <span class="argument">-xg</span>
<span class="comment"># Prints all global, exported variables.</span>

<span class="command">set</span> <span class="argument">foo</span> <span class="argument">hi</span>
<span class="comment"># Sets the value of the variable $foo to be 'hi'.</span>

<span class="command">set</span> <span class="argument">-e</span> <span class="argument">smurf</span>
<span class="comment"># Removes the variable $smurf</span>

<span class="command">set</span> <span class="argument">PATH</span><span class="argument">[4]</span> <span class="path">~/bin</span>
<span class="comment"># Changes the fourth element of the $PATH array to ~/bin</span>

<span class="command">if</span> <span class="command">set</span> <span class="argument">python_path</span> <span class="operator">(</span><span class="binary">which</span> <span class="argument">python</span><span class="operator">)</span>
    <span class="command">echo</span> <span class="string">"Python is at $python_path"</span>
<span class="command">end</span>
<span class="comment"># Outputs the path to Python if `which` returns true.</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="source"></a>
source - evaluate contents of file.</h1>
<h2><a class="anchor" id="source-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">source</span> <span class="argument">FILENAME</span> <span class="argument">[ARGUMENTS...]</span>
</pre><h2><a class="anchor" id="source-description"></a>
Description</h2>
<p><code>source</code> evaluates the commands of the specified file in the current shell. This is different from starting a new process to perform the commands (i.e. <code>fish &lt; FILENAME</code>) since the commands will be evaluated by the current shell, which means that changes in shell variables will affect the current shell. If additional arguments are specified after the file name, they will be inserted into the <code>$argv</code> variable. The <code>$argv</code> variable will not include the name of the sourced file.</p>
<p>If no file is specified, or if the file name '<code>-</code>' is used, stdin will be read.</p>
<p>The return status of <code>source</code> is the return status of the last job to execute. If something goes wrong while opening or reading the file, <code>source</code> exits with a non-zero status.</p>
<p><code>.</code> (a single period) is an alias for the <code>source</code> command. The use of <code>.</code> is deprecated in favour of <code>source</code>, and <code>.</code> will be removed in a future version of fish.</p>
<h2><a class="anchor" id="source-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">source</span> <span class="path">~/.config/fish/config.fish</span>
<span class="comment"># Causes fish to re-read its initialization file.</span>
</pre><h2><a class="anchor" id="Caveats"></a>
Caveats</h2>
<p>In fish versions prior to 2.3.0 the <code>$argv</code> variable would have a single element (the name of the sourced file) if no arguments are present. Otherwise it would contain arguments without the name of the sourced file. That behavior was very confusing and unlike other shells such as bash and zsh.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="status"></a>
status - query fish runtime information</h1>
<h2><a class="anchor" id="status-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">status</span> <span class="argument">[OPTION]</span>
</pre><h2><a class="anchor" id="status-description"></a>
Description</h2>
<p>With no arguments, <code>status</code> displays a summary of the current login and job control status of the shell.</p>
<p>The following options are available:</p>
<ul>
<li><code>-c</code> or <code>--is-command-substitution</code> returns 0 if fish is currently executing a command substitution.</li>
<li><code>-b</code> or <code>--is-block</code> returns 0 if fish is currently executing a block of code.</li>
<li><code>-i</code> or <code>--is-interactive</code> returns 0 if fish is interactive - that is, connected to a keyboard.</li>
<li><code>-l</code> or <code>--is-login</code> returns 0 if fish is a login shell - that is, if fish should perform login tasks such as setting up the PATH.</li>
<li><code>--is-full-job-control</code> returns 0 if full job control is enabled.</li>
<li><code>--is-interactive-job-control</code> returns 0 if interactive job control is enabled.</li>
<li><code>--is-no-job-control</code> returns 0 if no job control is enabled.</li>
<li><code>-f</code> or <code>--current-filename</code> prints the filename of the currently running script.</li>
<li><code>-n</code> or <code>--current-line-number</code> prints the line number of the currently running script.</li>
<li><code>-j CONTROLTYPE</code> or <code>--job-control=CONTROLTYPE</code> sets the job control type, which can be <code>none</code>, <code>full</code>, or <code>interactive</code>.</li>
<li><code>-t</code> or <code>--print-stack-trace</code> prints a stack trace of all function calls on the call stack.</li>
</ul>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="string"></a>
string - manipulate strings</h1>
<h2><a class="anchor" id="string-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">string</span> <span class="argument">length</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>] <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">sub</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-s</span> <span class="redirect">|</span> <span class="argument">--start</span><span class="operator">)</span> <span class="argument">START]</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-l</span> <span class="redirect">|</span> <span class="argument">--length</span><span class="operator">)</span> <span class="argument">LENGTH]</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>]
           <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">split</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-m</span> <span class="redirect">|</span> <span class="argument">--max</span><span class="operator">)</span> <span class="argument">MAX]</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-r</span> <span class="redirect">|</span> <span class="argument">--right</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>] <span class="argument">SEP</span>
             <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">join</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>] <span class="argument">SEP</span> <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">trim</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-l</span> <span class="redirect">|</span> <span class="argument">--left</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-r</span> <span class="redirect">|</span> <span class="argument">--right</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-c</span> <span class="redirect">|</span> <span class="argument">--chars</span> <span class="argument">CHARS</span><span class="operator">)</span>]
            <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>] <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">escape</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-n</span> <span class="redirect">|</span> <span class="argument">--no-quoted</span><span class="operator">)</span>] <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">match</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-a</span> <span class="redirect">|</span> <span class="argument">--all</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-i</span> <span class="redirect">|</span> <span class="argument">--ignore-case</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-r</span> <span class="redirect">|</span> <span class="argument">--regex</span><span class="operator">)</span>]
             <span class="argument">[</span><span class="operator">(</span><span class="argument">-n</span> <span class="redirect">|</span> <span class="argument">--index</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-v</span> <span class="redirect">|</span> <span class="argument">--invert</span><span class="operator">)</span>] <span class="argument">PATTERN</span> <span class="argument">[STRING...]</span>
<span class="command">string</span> <span class="argument">replace</span> <span class="argument">[</span><span class="operator">(</span><span class="argument">-a</span> <span class="redirect">|</span> <span class="argument">--all</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-i</span> <span class="redirect">|</span> <span class="argument">--ignore-case</span><span class="operator">)</span>] <span class="argument">[</span><span class="operator">(</span><span class="argument">-r</span> <span class="redirect">|</span> <span class="argument">--regex</span><span class="operator">)</span>]
               <span class="argument">[</span><span class="operator">(</span><span class="argument">-q</span> <span class="redirect">|</span> <span class="argument">--quiet</span><span class="operator">)</span>] <span class="argument">PATTERN</span> <span class="argument">REPLACEMENT</span> <span class="argument">[STRING...]</span>
</pre><h2><a class="anchor" id="string-description"></a>
Description</h2>
<p><code>string</code> performs operations on strings.</p>
<p>STRING arguments are taken from the command line unless standard input is connected to a pipe or a file, in which case they are read from standard input, one STRING per line. It is an error to supply STRING arguments on the command line and on standard input.</p>
<p>Arguments beginning with <code>-</code> are normally interpreted as switches; <code>--</code> causes the following arguments not to be treated as switches even if they begin with <code>-</code>. Switches and required arguments are recognized only on the command line.</p>
<p>Most subcommands accept a <code>-q</code> or <code>--quiet</code> switch, which suppresses the usual output but exits with the documented status.</p>
<p>In addition to the exit codes documented below, all the string subcommands exit with a value of 2 to indicate that an error occurred.</p>
<p>The following subcommands are available:</p>
<ul>
<li><code>length</code> reports the length of each string argument in characters. Exit status: 0 if at least one non-empty STRING was given, or 1 otherwise.</li>
<li><code>sub</code> prints a substring of each string argument. The start of the substring can be specified with <code>-s</code> or <code>--start</code> followed by a 1-based index value. Positive index values are relative to the start of the string and negative index values are relative to the end of the string. The default start value is 1. The length of the substring can be specified with <code>-l</code> or <code>--length</code>. If the length is not specified, the substring continues to the end of each STRING. Exit status: 0 if at least one substring operation was performed, 1 otherwise.</li>
<li><code>split</code> splits each STRING on the separator SEP, which can be an empty string. If <code>-m</code> or <code>--max</code> is specified, at most MAX splits are done on each STRING. If <code>-r</code> or <code>--right</code> is given, splitting is performed right-to-left. This is useful in combination with <code>-m</code> or <code>--max</code>. Exit status: 0 if at least one split was performed, or 1 otherwise.</li>
<li><code>join</code> joins its STRING arguments into a single string separated by SEP, which can be an empty string. Exit status: 0 if at least one join was performed, or 1 otherwise.</li>
<li><code>trim</code> removes leading and trailing whitespace from each STRING. If <code>-l</code> or <code>--left</code> is given, only leading whitespace is removed. If <code>-r</code> or <code>--right</code> is given, only trailing whitespace is trimmed. The <code>-c</code> or <code>--chars</code> switch causes the characters in CHARS to be removed instead of whitespace. Exit status: 0 if at least one character was trimmed, or 1 otherwise.</li>
<li><code>escape</code> escapes each STRING such that it can be passed back to <code>eval</code> to produce the original argument again. By default, all special characters are escaped, and quotes are used to simplify the output when possible. If <code>-n</code> or <code>--no-quote</code> is given, the simplifying quoted format is not used. Exit status: 0 if at least one string was escaped, or 1 otherwise.</li>
<li><code>match</code> tests each STRING against PATTERN and prints matching substrings. Only the first match for each STRING is reported unless <code>-a</code> or <code>--all</code> is given, in which case all matches are reported. Matching can be made case-insensitive with <code>-i</code> or <code>--ignore-case</code>. If <code>-n</code> or <code>--index</code> is given, each match is reported as a 1-based start position and a length. By default, PATTERN is interpreted as a glob pattern matched against each entire STRING argument. If <code>-r</code> or <code>--regex</code> is given, PATTERN is interpreted as a Perl-compatible regular expression. For a regular expression containing capturing groups, multiple items will be reported for each match, one for the entire match and one for each capturing group. If &ndash;invert or -v is used the selected lines will be only those which do not match the given glob pattern or regular expression. Exit status: 0 if at least one match was found, or 1 otherwise.</li>
<li><code>replace</code> is similar to <code>match</code> but replaces non-overlapping matching substrings with a replacement string and prints the result. By default, PATTERN is treated as a literal substring to be matched. If <code>-r</code> or <code>--regex</code> is given, PATTERN is interpreted as a Perl-compatible regular expression, and REPLACEMENT can contain C-style escape sequences like <code>\t</code> as well as references to capturing groups by number or name as <code>$n</code> or <code>${n}</code>. Exit status: 0 if at least one replacement was performed, or 1 otherwise.</li>
</ul>
<h2><a class="anchor" id="string-example"></a>
Examples</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">length</span> <span class="string">'hello, world'</span>
<span class="output">12</span>

<span class="prompt">&gt;</span> <span class="command">set</span> <span class="argument">str</span> <span class="argument">foo</span>
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">length</span> <span class="argument">-q</span> <span class="variable"><span class="operator">$</span>str</span><span class="redirect">;</span> <span class="command">echo</span> <span class="variable"><span class="operator">$</span>status</span>
0
<span class="comment"># Equivalent to test -n $str</span>
</pre> 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">sub</span> <span class="argument">--length</span> <span class="argument">2</span> <span class="argument">abcde</span>
<span class="output">ab</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">sub</span> <span class="argument">-s</span> <span class="argument">2</span> <span class="argument">-l</span> <span class="argument">2</span> <span class="argument">abcde</span>
<span class="output">bc</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">sub</span> <span class="argument">--start=-2</span> <span class="argument">abcde</span>
<span class="output">de</span>
</pre> 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">split</span> <span class="argument">.</span> <span class="file">example.com</span>
<span class="output">example</span>
<span class="output">com</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">split</span> <span class="argument">-r</span> <span class="argument">-m1</span> <span class="path">/</span> <span class="path">/usr/local/bin/fish</span>
<span class="output">/usr/local/bin</span>
<span class="output">fish</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">split</span> '' <span class="argument">abc</span>
<span class="output">a</span>
<span class="output">b</span>
<span class="output">c</span>
</pre> 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="binary">seq</span> <span class="argument">3</span> <span class="redirect">|</span> <span class="command">string</span> <span class="argument">join</span> <span class="argument">...</span>
<span class="output">1...2...3</span>
</pre> 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">trim</span> <span class="string">' abc  '</span>
<span class="output">abc</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">trim</span> <span class="argument">--right</span> <span class="argument">--chars=yz</span> <span class="argument">xyzzy</span> <span class="argument">zany</span>
<span class="output">x</span>
<span class="output">zan</span>
</pre> 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">echo</span> <span>\</span>x07 <span class="redirect">|</span> <span class="command">string</span> <span class="argument">escape</span>
<span>\</span>cg
</pre><h2><a class="anchor" id="string-example-match-glob"></a>
Match Glob Examples</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="string">'?'</span> <span class="argument">a</span>
<span class="output">a</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="string">'a*b'</span> <span class="argument">axxb</span>
<span class="output">axxb</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-i</span> <span class="string">'a??B'</span> <span class="argument">Axxb</span>
<span class="output">Axxb</span>

<span class="prompt">&gt;</span> <span class="command">echo</span> <span class="string">'ok?'</span> <span class="redirect">|</span> <span class="command">string</span> <span class="argument">match</span> <span class="string">'*<span>\</span>?'</span>
>_ <span class="output">ok?</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-r</span> <span class="argument">-v</span> <span class="string">"c.*[12]"</span> {<span class="argument">cat</span>,dog}<span class="operator">(</span><span class="binary">seq</span> <span class="argument">1</span> <span class="argument">4</span><span class="operator">)</span>
<span class="output">dog1</span>
<span class="output">dog2</span>
<span class="output">cat3</span>
<span class="output">dog3</span>
<span class="output">cat4</span>
<span class="output">dog4</span>
</pre><h2><a class="anchor" id="string-example-match-regex"></a>
Match Regex Examples</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-r</span> <span class="string">'cat|dog|fish'</span> <span class="string">'nice dog'</span>
<span class="output">dog</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-r</span> <span class="string">'<span class="operator">(</span><span>\</span>d<span>\</span>d?<span class="operator">)</span>:<span class="operator">(</span><span>\</span>d<span>\</span>d<span class="operator">)</span>:<span class="operator">(</span><span>\</span>d<span>\</span>d<span class="operator">)</span>'</span> 2:34:56
<span class="output">2:34:56</span>
<span class="output">2</span>
<span class="output">34</span>
<span class="output">56</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-r</span> <span class="string">'^<span class="operator">(</span><span>\</span>w{2,4}<span class="operator">)</span><span>\</span>g1$'</span> <span class="argument">papa</span> <span class="argument">mud</span> <span class="argument">murmur</span>
<span class="output">papa</span>
<span class="output">pa</span>
<span class="output">murmur</span>
<span class="output">mur</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-r</span> <span class="argument">-a</span> <span class="argument">-n</span> <span class="argument">at</span> <span class="argument">ratatat</span>
<span class="output">2 2</span>
<span class="output">4 2</span>
<span class="output">6 2</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">match</span> <span class="argument">-r</span> <span class="argument">-i</span> <span class="string">'0x[0-9a-f]{1,8}'</span> <span class="string">'int magic = 0xBadC0de;'</span>
<span class="output">0xBadC0de</span>
</pre><h2><a class="anchor" id="string-example-replace-literal"></a>
Replace Literal Examples</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">replace</span> <span class="argument">is</span> <span class="argument">was</span> <span class="string">'blue is my favorite'</span>
<span class="output">blue was my favorite</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">replace</span> <span class="argument">3rd</span> <span class="argument">last</span> <span class="argument">1st</span> <span class="argument">2nd</span> <span class="argument">3rd</span>
<span class="output">1st</span>
<span class="output">2nd</span>
<span class="output">last</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">replace</span> <span class="argument">-a</span> <span class="string">' '</span> _ <span class="string">'spaces to underscores'</span>
<span class="output">spaces_to_underscores</span>
</pre><h2><a class="anchor" id="string-example-replace-Regex"></a>
Replace Regex Examples</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">replace</span> <span class="argument">-r</span> <span class="argument">-a</span> <span class="string">'[^<span>\</span>d.]+'</span> <span class="string">' '</span> <span class="string">'0 one two 3.14 four 5x'</span>
<span class="output">0 3.14 5</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">replace</span> <span class="argument">-r</span> <span class="string">'<span class="operator">(</span><span>\</span>w+<span class="operator">)</span><span>\</span>s+<span class="operator">(</span><span>\</span>w+<span class="operator">)</span>'</span> <span class="string">'$2 $1 $$'</span> <span class="string">'left right'</span>
<span class="output">right left $</span>

<span class="prompt">&gt;</span> <span class="command">string</span> <span class="argument">replace</span> <span class="argument">-r</span> <span class="string">'<span>\</span>s*newline<span>\</span>s*'</span> <span class="string">'<span>\</span>n'</span> <span class="string">'put a newline here'</span>
<span class="output">put a</span>
<span class="output">here</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="suspend"></a>
suspend - suspend the current shell</h1>
<h2><a class="anchor" id="suspend-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">suspend</span> <span class="argument">[</span><span class="argument">--force</span>]
</pre><h2><a class="anchor" id="suspend-description"></a>
Description</h2>
<p><code>suspend</code> suspends execution of the current shell by sending it a SIGTSTP signal, returning to the controlling process. It can be resumed later by sending it a SIGCONT. In order to prevent suspending a shell that doesn't have a controlling process, it will not suspend a the shell if it is a login shell or if <code>$SHLVL</code> is less <code>$suspend_minimum_SHLVL</code>, which defaults to three. This test is skipped if the <code>--force</code> option is given or the shell is not interactive.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="switch"></a>
switch - conditionally execute a block of commands</h1>
<h2><a class="anchor" id="switch-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">switch</span> <span class="argument">VALUE</span><span class="redirect">;</span> <span class="argument">[</span><span class="command">case</span> <span class="argument">[WILDCARD...]</span><span class="redirect">;</span> <span class="argument">[COMMANDS...]</span><span class="redirect">;</span> <span class="argument">...]</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="switch-description"></a>
Description</h2>
<p><code>switch</code> performs one of several blocks of commands, depending on whether a specified value equals one of several wildcarded values. <code>case</code> is used together with the <code>switch</code> statement in order to determine which block should be executed.</p>
<p>Each <code>case</code> command is given one or more parameters. The first <code>case</code> command with a parameter that matches the string specified in the switch command will be evaluated. <code>case</code> parameters may contain wildcards. These need to be escaped or quoted in order to avoid regular wildcard expansion using filenames.</p>
<p>Note that fish does not fall through on case statements. Only the first matching case is executed.</p>
<p>Note that command substitutions in a case statement will be evaluated even if its body is not taken. All substitutions, including command substitutions, must be performed before the value can be compared against the parameter.</p>
<h2><a class="anchor" id="switch-example"></a>
Example</h2>
<p>If the variable $animal contains the name of an animal, the following code would attempt to classify it:</p>
 
 <pre class="fish">
<span class="command">switch</span> <span class="variable"><span class="operator">$</span>animal</span>
    <span class="command">case</span> <span class="argument">cat</span>
        <span class="command">echo</span> <span class="argument">evil</span>
    <span class="command">case</span> <span class="argument">wolf</span> <span class="argument">dog</span> <span class="argument">human</span> <span class="argument">moose</span> <span class="argument">dolphin</span> <span class="argument">whale</span>
        <span class="command">echo</span> <span class="argument">mammal</span>
    <span class="command">case</span> <span class="argument">duck</span> <span class="argument">goose</span> <span class="argument">albatross</span>
        <span class="command">echo</span> <span class="argument">bird</span>
    <span class="command">case</span> <span class="argument">shark</span> <span class="argument">trout</span> <span class="argument">stingray</span>
        <span class="command">echo</span> <span class="argument">fish</span>
    <span class="command">case</span> <span class="string">'*'</span>
        <span class="command">echo</span> <span class="argument">I</span> <span class="argument">have</span> <span class="argument">no</span> <span class="argument">idea</span> <span class="argument">what</span> <span class="argument">a</span> <span class="variable"><span class="operator">$</span>animal</span> <span class="argument">is</span>
<span class="command">end</span>
</pre><p>If the above code was run with <code>$animal</code> set to <code>whale</code>, the output would be <code>mammal</code>.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="test"></a>
test - perform tests on files and text</h1>
<h2><a class="anchor" id="test-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">test</span> <span class="argument">[EXPRESSION]</span>
[ <span class="argument">[EXPRESSION]</span> <span class="argument">]</span>
</pre><h2><a class="anchor" id="test-description"></a>
Description</h2>
<p>Tests the expression given and sets the exit status to 0 if true, and 1 if false. An expression is made up of one or more operators and their arguments.</p>
<p>The first form (<code>test</code>) is preferred. For compatibility with other shells, the second form is available: a matching pair of square brackets (<code>[ [EXPRESSION ] ]</code>).</p>
<p>This test is mostly POSIX-compatible.</p>
<h2><a class="anchor" id="test-files"></a>
Operators for files and directories</h2>
<ul>
<li><code>-b FILE</code> returns true if <code>FILE</code> is a block device.</li>
<li><code>-c FILE</code> returns true if <code>FILE</code> is a character device.</li>
<li><code>-d FILE</code> returns true if <code>FILE</code> is a directory.</li>
<li><code>-e FILE</code> returns true if <code>FILE</code> exists.</li>
<li><code>-f FILE</code> returns true if <code>FILE</code> is a regular file.</li>
<li><code>-g FILE</code> returns true if <code>FILE</code> has the set-group-ID bit set.</li>
<li><code>-G FILE</code> returns true if <code>FILE</code> exists and has the same group ID as the current user.</li>
<li><code>-L FILE</code> returns true if <code>FILE</code> is a symbolic link.</li>
<li><code>-O FILE</code> returns true if <code>FILE</code> exists and is owned by the current user.</li>
<li><code>-p FILE</code> returns true if <code>FILE</code> is a named pipe.</li>
<li><code>-r FILE</code> returns true if <code>FILE</code> is marked as readable.</li>
<li><code>-s FILE</code> returns true if the size of <code>FILE</code> is greater than zero.</li>
<li><code>-S FILE</code> returns true if <code>FILE</code> is a socket.</li>
<li><code>-t FD</code> returns true if the file descriptor <code>FD</code> is a terminal (TTY).</li>
<li><code>-u FILE</code> returns true if <code>FILE</code> has the set-user-ID bit set.</li>
<li><code>-w FILE</code> returns true if <code>FILE</code> is marked as writable; note that this does not check if the filesystem is read-only.</li>
<li><code>-x FILE</code> returns true if <code>FILE</code> is marked as executable.</li>
</ul>
<h2><a class="anchor" id="test-strings"></a>
Operators for text strings</h2>
<ul>
<li><code>STRING1 = STRING2</code> returns true if the strings <code>STRING1</code> and <code>STRING2</code> are identical.</li>
<li><code>STRING1 != STRING2</code> returns true if the strings <code>STRING1</code> and <code>STRING2</code> are not identical.</li>
<li><code>-n STRING</code> returns true if the length of <code>STRING</code> is non-zero.</li>
<li><code>-z STRING</code> returns true if the length of <code>STRING</code> is zero.</li>
</ul>
<h2><a class="anchor" id="test-numbers"></a>
Operators to compare and examine numbers</h2>
<ul>
<li><code>NUM1 -eq NUM2</code> returns true if <code>NUM1</code> and <code>NUM2</code> are numerically equal.</li>
<li><code>NUM1 -ne NUM2</code> returns true if <code>NUM1</code> and <code>NUM2</code> are not numerically equal.</li>
<li><code>NUM1 -gt NUM2</code> returns true if <code>NUM1</code> is greater than <code>NUM2</code>.</li>
<li><code>NUM1 -ge NUM2</code> returns true if <code>NUM1</code> is greater than or equal to <code>NUM2</code>.</li>
<li><code>NUM1 -lt NUM2</code> returns true if <code>NUM1</code> is less than <code>NUM2</code>.</li>
<li><code>NUM1 -le NUM2</code> returns true if <code>NUM1</code> is less than or equal to <code>NUM2</code>.</li>
</ul>
<p>Note that only integers are supported. For more complex mathematical operations, including fractions, the <code>env</code> program may be useful. Consult the documentation for your operating system.</p>
<h2><a class="anchor" id="test-combinators"></a>
Operators to combine expressions</h2>
<ul>
<li><code>COND1 -a COND2</code> returns true if both <code>COND1</code> and <code>COND2</code> are true.</li>
<li><code>COND1 -o COND2</code> returns true if either <code>COND1</code> or <code>COND2</code> are true.</li>
</ul>
<p>Expressions can be inverted using the <code>!</code> operator:</p>
<ul>
<li><code>! EXPRESSION</code> returns true if <code>EXPRESSION</code> is false, and false if <code>EXPRESSION</code> is true.</li>
</ul>
<p>Expressions can be grouped using parentheses.</p>
<ul>
<li><p class="startli"><code>( EXPRESSION )</code> returns the value of <code>EXPRESSION</code>.</p>
<p class="startli">Note that parentheses will usually require escaping with <code>\(</code> to avoid being interpreted as a command substitution.</p>
</li>
</ul>
<h2><a class="anchor" id="test-example"></a>
Examples</h2>
<p>If the <code>/tmp</code> directory exists, copy the <code>/etc/motd</code> file to it:</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="argument">-d</span> <span class="path">/tmp</span>
    <span class="binary">cp</span> <span class="path">/etc/motd</span> <span class="path">/tmp/motd</span>
<span class="command">end</span>
</pre><p>If the variable <code>MANPATH</code> is defined and not empty, print the contents. (If <code>MANPATH</code> is not defined, then it will expand to zero arguments, unless quoted.)</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="argument">-n</span> <span class="string">"$MANPATH"</span>
    <span class="command">echo</span> <span class="variable"><span class="operator">$</span>MANPATH</span>
<span class="command">end</span>
</pre><p>Parentheses and the <code>-o</code> and <code>-a</code> operators can be combined to produce more complicated expressions. In this example, success is printed if there is a <code>/foo</code> or <code>/bar</code> file as well as a <code>/baz</code> or <code>/bat</code> file.</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="operator"><span>\</span><span class="operator">(</span></span> <span class="argument">-f</span> <span class="path">/foo</span> <span class="argument">-o</span> <span class="argument">-f</span> <span class="path">/bar</span> <span class="operator"><span>\</span><span class="operator">)</span></span> <span class="argument">-a</span> <span class="operator"><span>\</span><span class="operator">(</span></span> <span class="argument">-f</span> <span class="path">/baz</span> <span class="argument">-o</span> <span class="argument">-f</span> <span class="path">/bat</span> <span class="operator"><span>\</span><span class="operator">)</span></span>
    <span class="command">echo</span> <span class="argument">Success.</span>
<span class="command">end</span><span class="argument">.</span>
</pre><p>Numerical comparisons will simply fail if one of the operands is not a number:</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="argument">42</span> <span class="argument">-eq</span> <span class="string">"The answer to life, the universe and everything"</span>
    <span class="command">echo</span> <span class="argument">So</span> <span class="argument">long</span> <span class="argument">and</span> <span class="argument">thanks</span> <span class="command">for</span> <span class="argument">all</span> <span class="argument">the</span> <span class="argument">fish</span> <span class="comment">## will not be executed</span>
<span class="command">end</span>
</pre><p>A common comparison is with $status:</p>
 
 <pre class="fish">
<span class="command">if</span> <span class="command">test</span> <span class="variable"><span class="operator">$</span>status</span> <span class="argument">-eq</span> <span class="argument">0</span>
    <span class="command">echo</span> <span class="string">"Previous command succeeded"</span>
<span class="command">end</span>
</pre><h2><a class="anchor" id="test-standards"></a>
Standards</h2>
<p><code>test</code> implements a subset of the <a href="http://www.unix.com/man-page/POSIX/1/test/">IEEE Std 1003.1-2008 (POSIX.1) standard</a>. The following exceptions apply:</p>
<ul>
<li>The <code>&lt;</code> and <code>&gt;</code> operators for comparing strings are not implemented.</li>
<li><p class="startli">Because this test is a shell builtin and not a standalone utility, using the -c flag on a special file descriptors like standard input and output may not return the same result when invoked from within a pipe as one would expect when invoking the <code>test</code> utility in another shell.</p>
<p class="startli">In cases such as this, one can use <code>command</code> <code>test</code> to explicitly use the system's standalone <code>test</code> rather than this <code>builtin</code> <code>test</code>.</p>
</li>
</ul>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="trap"></a>
trap - perform an action when the shell receives a signal</h1>
<h2><a class="anchor" id="trap-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">trap</span> <span class="argument">[OPTIONS]</span> <span class="argument">[</span><span class="argument">[ARG]</span> <span class="argument">SIGSPEC</span> <span class="argument">...</span> <span class="argument">]</span>
</pre><h2><a class="anchor" id="trap-description"></a>
Description</h2>
<p><code>trap</code> is a wrapper around the fish event delivery framework. It exists for backwards compatibility with POSIX shells. For other uses, it is recommended to define an <a href="index.html#event">event handler</a>.</p>
<p>The following parameters are available:</p>
<ul>
<li><code>ARG</code> is the command to be executed on signal delivery.</li>
<li><code>SIGSPEC</code> is the name of the signal to trap.</li>
<li><code>-l</code> or <code>--list-signals</code> prints a list of signal names.</li>
<li><code>-p</code> or <code>--print</code> prints all defined signal handlers.</li>
</ul>
<p>If <code>ARG</code> and <code>SIGSPEC</code> are both specified, <code>ARG</code> is the command to be executed when the signal specified by <code>SIGSPEC</code> is delivered.</p>
<p>If <code>ARG</code> is absent (and there is a single SIGSPEC) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell). If <code>ARG</code> is the null string the signal specified by each <code>SIGSPEC</code> is ignored by the shell and by the commands it invokes.</p>
<p>If <code>ARG</code> is not present and <code>-p</code> has been supplied, then the trap commands associated with each <code>SIGSPEC</code> are displayed. If no arguments are supplied or if only <code>-p</code> is given, <code>trap</code> prints the list of commands associated with each signal.</p>
<p>Signal names are case insensitive and the <code>SIG</code> prefix is optional.</p>
<p>The return status is 1 if any <code>SIGSPEC</code> is invalid; otherwise trap returns 0.</p>
<h2><a class="anchor" id="trap-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">trap</span> <span class="string">"status --print-stack-trace"</span> <span class="argument">SIGUSR1</span>
<span class="comment"># Prints a stack trace each time the SIGUSR1 signal is sent to the shell.</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="true"></a>
true - return a successful result</h1>
<h2><a class="anchor" id="true-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">true</span>
</pre><h2><a class="anchor" id="true-description"></a>
Description</h2>
<p><code>true</code> sets the exit status to 0.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="type"></a>
type - indicate how a command would be interpreted</h1>
<h2><a class="anchor" id="type-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">type</span> <span class="argument">[OPTIONS]</span> <span class="argument">NAME</span> <span class="argument">[NAME <span class="argument">...]</span></span>
</pre><h2><a class="anchor" id="type-description"></a>
Description</h2>
<p>With no options, <code>type</code> indicates how each <code>NAME</code> would be interpreted if used as a command name.</p>
<p>The following options are available:</p>
<ul>
<li><code>-a</code> or <code>--all</code> prints all of possible definitions of the specified names.</li>
<li><code>-f</code> or <code>--no-functions</code> suppresses function and builtin lookup.</li>
<li><code>-t</code> or <code>--type</code> prints <code>function</code>, <code>builtin</code>, or <code>file</code> if <code>NAME</code> is a shell function, builtin, or disk file, respectively.</li>
<li><code>-p</code> or <code>--path</code> returns the name of the disk file that would be executed, or nothing if <code>type -t name</code> would not return <code>file</code>.</li>
<li><code>-P</code> or <code>--force-path</code> returns the name of the disk file that would be executed, or nothing if no file with the specified name could be found in the <code>$PATH</code>.</li>
<li><code>-q</code> or <code>--quiet</code> suppresses all output; this is useful when testing the exit status.</li>
</ul>
<h2><a class="anchor" id="type-example"></a>
Example</h2>
 
 <pre class="fish cli-dark">
<span class="prompt">&gt;</span> <span class="command">type</span> <span class="argument">fg</span>
<span class="output">fg is a builtin</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="ulimit"></a>
ulimit - set or get resource usage limits</h1>
<h2><a class="anchor" id="ulimit-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">ulimit</span> <span class="argument">[OPTIONS]</span> <span class="argument">[LIMIT]</span>
</pre><h2><a class="anchor" id="ulimit-description"></a>
Description</h2>
<p><code>ulimit</code> builtin sets or outputs the resource usage limits of the shell and any processes spawned by it. If a new limit value is omitted, the current value of the limit of the resource is printed; otherwise, the specified limit is set to the new value.</p>
<p>Use one of the following switches to specify which resource limit to set or report:</p>
<ul>
<li><code>-c</code> or <code>--core-size</code>: the maximum size of core files created. By setting this limit to zero, core dumps can be disabled.</li>
<li><code>-d</code> or <code>--data-size</code>: the maximum size of a process' data segment.</li>
<li><code>-f</code> or <code>--file-size</code>: the maximum size of files created by the shell.</li>
<li><code>-l</code> or <code>--lock-size</code>: the maximum size that may be locked into memory.</li>
<li><code>-m</code> or <code>--resident-set-size</code>: the maximum resident set size.</li>
<li><code>-n</code> or <code>--file-descriptor-count</code>: the maximum number of open file descriptors (most systems do not allow this value to be set).</li>
<li><code>-s</code> or <code>--stack-size</code>: the maximum stack size.</li>
<li><code>-t</code> or <code>--cpu-time</code>: the maximum amount of CPU time in seconds.</li>
<li><code>-u</code> or <code>--process-count</code>: the maximum number of processes available to a single user.</li>
<li><code>-v</code> or <code>--virtual-memory-size</code> The maximum amount of virtual memory available to the shell.</li>
</ul>
<p>Note that not all these limits are available in all operating systems.</p>
<p>The value of limit can be a number in the unit specified for the resource or one of the special values <code>hard</code>, <code>soft</code>, or <code>unlimited</code>, which stand for the current hard limit, the current soft limit, and no limit, respectively.</p>
<p>If limit is given, it is the new value of the specified resource. If no option is given, then <code>-f</code> is assumed. Values are in kilobytes, except for <code>-t</code>, which is in seconds and <code>-n</code> and <code>-u</code>, which are unscaled values. The return status is 0 unless an invalid option or argument is supplied, or an error occurs while setting a new limit.</p>
<p><code>ulimit</code> also accepts the following switches that determine what type of limit to set:</p>
<ul>
<li><code>-H</code> or <code>--hard</code> sets hard resource limit</li>
<li><code>-S</code> or <code>--soft</code> sets soft resource limit</li>
</ul>
<p>A hard limit can only be decreased. Once it is set it cannot be increased; a soft limit may be increased up to the value of the hard limit. If neither -H nor -S is specified, both the soft and hard limits are updated when assigning a new limit value, and the soft limit is used when reporting the current value.</p>
<p>The following additional options are also understood by <code>ulimit</code>:</p>
<ul>
<li><code>-a</code> or <code>--all</code> prints all current limits</li>
</ul>
<p>The <code>fish</code> implementation of <code>ulimit</code> should behave identically to the implementation in bash, except for these differences:</p>
<ul>
<li>Fish <code>ulimit</code> supports GNU-style long options for all switches</li>
<li>Fish <code>ulimit</code> does not support the <code>-p</code> option for getting the pipe size. The bash implementation consists of a compile-time check that empirically guesses this number by writing to a pipe and waiting for SIGPIPE. Fish does not do this because it this method of determining pipe size is unreliable. Depending on bash version, there may also be further additional limits to set in bash that do not exist in fish.</li>
<li>Fish <code>ulimit</code> does not support getting or setting multiple limits in one command, except reporting all values using the -a switch</li>
</ul>
<h2><a class="anchor" id="ulimit-example"></a>
Example</h2>
<p><code>ulimit -Hs 64</code> sets the hard stack size limit to 64 kB.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="umask"></a>
umask - set or get the file creation mode mask</h1>
<h2><a class="anchor" id="umask-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">umask</span> <span class="argument">[OPTIONS]</span> <span class="argument">[MASK]</span>
</pre><h2><a class="anchor" id="umask-description"></a>
Description</h2>
<p><code>umask</code> displays and manipulates the "umask", or file creation mode mask, which is used to restrict the default access to files.</p>
<p>The umask may be expressed either as an octal number, which represents the rights that will be removed by default, or symbolically, which represents the only rights that will be granted by default.</p>
<p>Access rights are explained in the manual page for the <code>chmod</code>(1) program.</p>
<p>With no parameters, the current file creation mode mask is printed as an octal number.</p>
<ul>
<li><code>-h</code> or <code>--help</code> prints this message.</li>
<li><code>-S</code> or <code>--symbolic</code> prints the umask in symbolic form instead of octal form.</li>
<li><code>-p</code> or <code>--as-command</code> outputs the umask in a form that may be reused as input</li>
</ul>
<p>If a numeric mask is specified as a parameter, the current shell's umask will be set to that value, and the rights specified by that mask will be removed from new files and directories by default.</p>
<p>If a symbolic mask is specified, the desired permission bits, and not the inverse, should be specified. A symbolic mask is a comma separated list of rights. Each right consists of three parts:</p>
<ul>
<li>The first part specifies to whom this set of right applies, and can be one of <code>u</code>, <code>g</code>, <code>o</code> or <code>a</code>, where <code>u</code> specifies the user who owns the file, <code>g</code> specifies the group owner of the file, <code>o</code> specific other users rights and <code>a</code> specifies all three should be changed.</li>
<li>The second part of a right specifies the mode, and can be one of <code>=</code>, <code>+</code> or <code>-</code>, where <code>=</code> specifies that the rights should be set to the new value, <code>+</code> specifies that the specified right should be added to those previously specified and <code>-</code> specifies that the specified rights should be removed from those previously specified.</li>
<li>The third part of a right specifies what rights should be changed and can be any combination of <code>r</code>, <code>w</code> and <code>x</code>, representing read, write and execute rights.</li>
</ul>
<p>If the first and second parts are skipped, they are assumed to be <code>a</code> and <code>=</code>, respectively. As an example, <code>r,u+w</code> means all users should have read access and the file owner should also have write access.</p>
<p>Note that symbolic masks currently do not work as intended.</p>
<h2><a class="anchor" id="umask-example"></a>
Example</h2>
<p><code>umask 177</code> or <code>umask u=rw</code> sets the file creation mask to read and write for the owner and no permissions at all for any other users.</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="vared"></a>
vared - interactively edit the value of an environment variable</h1>
<h2><a class="anchor" id="vared-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">vared</span> <span class="argument">VARIABLE_NAME</span>
</pre><h2><a class="anchor" id="vared-description"></a>
Description</h2>
<p><code>vared</code> is used to interactively edit the value of an environment variable. Array variables as a whole can not be edited using <code>vared</code>, but individual array elements can.</p>
<h2><a class="anchor" id="vared-example"></a>
Example</h2>
<p><code>vared PATH[3]</code> edits the third element of the PATH array</p>
<p>Back to <a href="index.html#toc-commands">index</a>. </p><hr/>
 <h1><a class="anchor" id="while"></a>
while - perform a command multiple times</h1>
<h2><a class="anchor" id="while-synopsis"></a>
Synopsis</h2>
 
 <pre class="fish synopsis">
<span class="command">while</span> <span class="argument">CONDITION</span><span class="redirect">;</span> <span class="argument">COMMANDS...</span><span class="redirect">;</span> <span class="command">end</span>
</pre><h2><a class="anchor" id="while-description"></a>
Description</h2>
<p><code>while</code> repeatedly executes <code>CONDITION</code>, and if the exit status is 0, then executes <code>COMMANDS</code>.</p>
<p>If the exit status of <code>CONDITION</code> is non-zero on the first iteration, <code>COMMANDS</code> will not be executed at all.</p>
<p>You can use <a href="#and"><code>and</code></a> or <a href="#and"><code>or</code></a> for complex conditions. Even more complex control can be achieved with <code>while true</code> containing a <a href="#break">break</a>.</p>
<h2><a class="anchor" id="while-example"></a>
Example</h2>
 
 <pre class="fish">
<span class="command">while</span> <span class="argument">test</span> <span class="argument">-f</span> <span class="file">foo.txt</span><span class="redirect">;</span> <span class="command">or</span> <span class="command">test</span> <span class="argument">-f</span> <span class="file">bar.txt</span> ; <span class="command">echo</span> <span class="argument">file</span> <span class="argument">exists</span><span class="redirect">;</span> <span class="command">sleep</span> <span class="argument">10</span><span class="redirect">;</span> <span class="command">end</span>
<span class="comment"># outputs 'file exists' at 10 second intervals as long as the file foo.txt or bar.txt exists.</span>
</pre><p>Back to <a href="index.html#toc-commands">index</a>.</p>

</div>
 </div></div><!-- contents -->
</body>
</html>

Hry