{{Short description|User-friendly interactive Unix shell}} {{Multiple issues| {{More citations needed|date=May 2019}} {{Tone|date=July 2024}} {{Missing information|Fish's history|date=March 2022}} }} {{Lowercase title}}
{{Use dmy dates|date=November 2025}} {{Infobox software | name = fish | logo = Fish icon.png | screenshot = fish shell 4.0.0 screenshot.webp | screenshot size = 300px | caption = Version 4.0.0 of fish | author = Axel Liljencrantz | developer = Fish-shell developers<ref>{{cite web |title=fish shell team members |url=https://github.com/orgs/fish-shell/people |access-date=10 November 2025 |publisher=GitHub.com}}</ref> | released = {{release date and age|2005|02|13|df=yes}} | latest release version = {{wikidata|property|preferred|references|edit|Q307263|P348|P548=Q2804309}} | latest release date = {{wikidata|qualifier|preferred|single|Q307263|P348|P548=Q2804309|P577}} | programming language = Rust since v4.0,<ref>{{cite web |date=17 December 2024 |title=fish-shell 4.0b1, now in Rust |url=https://fishshell.com/blog/fish-4b/ |access-date=18 December 2024 |website=fishshell.com}}</ref> C++ up to v3.7.1<ref>{{cite web |title=fish 4.0.0 (released February 27, 2025) |url=https://fishshell.com/docs/current/relnotes.html#fish-4-0-0-released-february-27-2025 |access-date=16 August 2025 |website=fishshell.com}}</ref> C up to 1.8<ref>{{cite web |title=fish-shell/fish-shell: Commits from 2005-04-07 to 2006-12-31 |url=https://github.com/fish-shell/fish-shell/commits/master/?since=2005-04-07&until=2006-12-31 |website=GitHub |access-date=2026-05-07}}</ref><ref>{{cite web |title=Fish Shell Rust Port |url=https://fishshell.com/blog/rustport/ |website=fishshell.com |date=2023-04-24 |access-date=2026-05-07}}</ref> | operating system = Unix-like | genre = Unix shell | license = GPL-2.0-only<ref>{{Cite web |title=License |url=https://fishshell.com/docs/current/license.html |access-date=10 November 2025 |website=fishshell.com}}</ref> | website = {{URL|https://fishshell.com}} }} '''fish''' ('''friendly interactive shell'''; stylized in lowercase) is a Unix-like shell with a focus on interactivity and usability. fish is designed to be feature-rich by default, rather than highly configurable,<ref>{{cite web |last=Liljencrantz |first=Axel |date=17 May 2005 |title=Fish – A user-friendly shell |url=https://lwn.net/Articles/136232 |access-date=24 March 2010 |publisher=Linux Weekly News}}</ref> and does not adhere to POSIX shell standards by design.<ref>{{cite web |title=Fish docs: design |url=https://fishshell.com/docs/current/design.html |access-date=9 April 2021 |website=fishshell.com}}</ref>
==Features== fish displays incremental suggestions as the user types, based on command history and the current directory. This functions similarly to Bash's {{keypress|Ctrl|R}} history search, but is always on, giving the user continuous feedback while typing commands. fish also includes feature-rich tab completion, with support for expanding file paths (with wildcards and brace expansion), environment variables, and command-specific completions. Command-specific completions, including options with descriptions, can be to some extent generated from the commands' man pages, but custom completions can also be included with software or written by users of the shell.<ref>{{Cite web |title=Writing your own completions |url=https://fishshell.com/docs/current/completions.html |url-status=live |archive-url=https://web.archive.org/web/20240831075627/https://fishshell.com/docs/current/completions.html |archive-date=31 August 2024 |access-date=10 November 2025 |website=fishshell.com}}</ref>
The creator of fish preferred to add new features as commands rather than syntax. This made features more discoverable, as the built-in features allow searching commands with options and help texts. Functions can also include human readable descriptions. A special ''help'' command gives access to all the fish documentation in the user's web browser.<ref>{{Cite web |date=13 November 2006 |title=CLI Magic: Enhancing the shell with fish |url=https://www.linux.com/news/cli-magic-enhancing-shell-fish/ |access-date=10 November 2025 |website=Linux.com |language=en-US}}</ref>
==Syntax== The syntax resembles a POSIX compatible shell (such as Bash), but deviates in many ways<ref name="indepthfish">{{cite web |last1=Paul |first1=Ryan |date=19 December 2005 |title=An in-depth look at fish: the friendly interactive shell |url=https://arstechnica.com/information-technology/2005/12/linux-20051218/2/ |access-date=10 March 2015 |website=Ars Technica |quote=the Posix syntax has several missing or badly implemented features, including variable scoping, arrays, and functions. For this reason, fish strays from the Posix syntax in several important places.}}</ref>
<syntaxhighlight lang="fish"> # Variable assignment # # Set the variable 'foo' to the value 'bar'. # fish doesn't use the = operator, which is inherently whitespace sensitive. # The 'set' command extends to work with arrays, scoping, etc.
> set foo bar > echo $foo bar
# Command substitution # # Assign the output of the command 'pwd' into the variable 'wd'. # fish doesn't use backticks (``), which can't be nested and may be confused with single quotes (' ').
> set wd (pwd) > set wd $(pwd) # since version 3.4 > echo $wd ~
# Array variables. 'A' becomes an array with 5 values: > set A 3 5 7 9 12 # Array slicing. 'B' becomes the first two elements of 'A': > set B $A[1 2] > echo $B 3 5 # You can index with other arrays and even command # substitution output: > echo $A[(seq 3)] 3 5 7 # Erase the third and fifth elements of 'A' > set --erase A[$B] > echo $A 3 5 9
# for-loop, convert jpegs to pngs > for i in *.jpg convert $i (basename $i .jpg).png end
# fish supports multi-line history and editing. # Semicolons work like newlines: > for i in *.jpg; convert $i (basename $i .jpg).png; end
# while-loop, read lines /etc/passwd and output the fifth # colon-separated field from the file. This should be # the user description. > while read line set arr (echo $line|tr : \n) echo $arr[5] end < /etc/passwd
# String replacement (replacing all i by I) > string replace -a "i" "I" "Wikipedia" WIkIpedIa </syntaxhighlight>
=== No implicit subshell === Some language constructs, like pipelines, functions and loops, have been implemented using so called subshells in other shell languages. Subshells are child programs that run a few commands to perform a task, then exit back to the parent shell. This implementation detail typically has the side effect that any state changes made in the subshell, such as variable assignments, do not propagate to the main shell. fish never creates subshells for language features; all builtins happen within the parent shell. <syntaxhighlight lang="fish"> # This will not work in many other shells, since the 'read' builtin # will run in its own subshell. In Bash, the right side of the pipe # can't have any side effects. In ksh, the below command works, but # the left side can't have any side effects. In fish and zsh, both # sides can have side effects. > cat *.txt | read line </syntaxhighlight>
==== Variable assignment example ==== This Bash example doesn't do what it seems: because the loop body is a subshell, the update to <code>$found</code> is not persistent. <syntaxhighlight lang="bash"> found='' cat /etc/fstab | while read dev mnt rest; do if test "$mnt" = "/"; then found="$dev" fi done </syntaxhighlight>
Workaround: <syntaxhighlight lang="bash"> found='' while read dev mnt rest; do if test "$mnt" = "/"; then found="$dev" fi done < /etc/fstab </syntaxhighlight>
Fish example: <syntaxhighlight lang="fish"> set found '' cat /etc/fstab | while read dev mnt rest if test "$mnt" = "/" set found $dev end end </syntaxhighlight>
==Universal variables== fish has a feature known as universal variables, which allows a user to permanently assign a value to a variable across all the user's running fish shells. The variable value is remembered across logouts and reboots, and updates are immediately propagated to all running shells. <syntaxhighlight lang="fish"> # This will make emacs the default text editor. The '--universal' (or '-U') tells fish to # make this a universal variable. > set --universal EDITOR emacs
# This command will make the current working directory part of the fish # prompt turn blue on all running fish instances. > set --universal fish_color_cwd blue </syntaxhighlight>
==Other features== * Advanced tab completion (with support for writing custom completions). * Syntax highlighting with extensive error checking. * Support for the X clipboard. * Smart terminal handling based on terminfo. * Searchable command history. * Web-based configuration (fish_config).<ref>{{Cite web |title=fish_config – start the web-based configuration interface |url=https://fishshell.com/docs/current/cmds/fish_config.html |access-date=10 November 2025 |website=fishshell.com}}</ref>
==Bash/fish translation table== {| class="wikitable" |- ! style="width: 15%" | Feature !! style="width: 25%" | Bash syntax !! style="width: 45%" | fish syntax !! style="width: 15%" |Comment |- | variable expansion:<br />with word splitting and glob interpretation || $var or ${var[@]} or ${var[*]} | {{No|deliberately omitted}} || Identified as a primary cause of bugs in posix compatible shell languages<ref name="bash_pitfalls" /> |- | variable expansion:<br />scalar || "$var" | {{No|deliberately omitted}} || Every variable is an array |- | variable expansion:<br />array || "${var[@]}" || $var |rowspan=2| Quoting not necessary to suppress word splitting and glob interpretation. Instead, quoting signifies serialization. |- | variable expansion:<br />as a space separated string || "${var[*]}" || "$var" |- | edit line in text editor || {{keypress|Ctrl|X}},{{keypress|Ctrl|E}} || {{keypress|Alt|E}} || Upon invocation, moves line input to a text editor |- | evaluate line input || {{keypress|Ctrl|Alt|E}} || {{n/a}}<ref>{{cite web |author=dag |date=16 May 2013 |title=RFC: Add binding to expand/evaluate tokens on commandline |url=https://github.com/fish-shell/fish-shell/issues/751 |access-date=9 April 2021 |website=GitHub}}</ref> || Evaluates expressions in-place on the line editor |- | history completion || {{keypress|Ctrl|R}} || {{Yes|implicit}} || |- | history substitution || !! || {{No|deliberately omitted}} || Not discoverable |- | explicit subshell || (expression) | fish -c expression |- | command substitution || "$(expression)" | <code>"$(expression)"</code> or <code>(expression | string collect)</code> | |- | process substitution || <(expression) | (expression | psub) |rowspan=5| Command, not syntax |- | logical operators || <syntaxhighlight lang="bash"> !cmd && echo FAIL || echo OK </syntaxhighlight> | <syntaxhighlight lang="fish"> not command and echo FAIL or echo OK</syntaxhighlight> |- | variable assignment || var=value | <syntaxhighlight lang="fish"> set var value </syntaxhighlight> |- | string processing:<br />replace || "${HOME/alice/bob}" || string replace alice bob $HOME |- | string processing:<br />remove prefix or suffix pattern, non-greedily or greedily || <syntaxhighlight lang="bash"> var=a.b.c "${var#*.}" #b.c "${var##*.}" #c "${var%.*}" #a.b "${var%%.*}" #a </syntaxhighlight> |class="nowrap"| <syntaxhighlight lang="fish"> string replace --regex '.*?\.(.*)' '$1' a.b.c #b.c string replace --regex '.*\.(.*)' '$1' a.b.c #c string replace --regex '(.*)\..*' '$1' a.b.c #a.b string replace --regex '(.*?)\..*' '$1' a.b.c #a </syntaxhighlight> |- | export variable || export var | set --export var |rowspan=5| Options discoverable via tab completion |- | function-local variable || local var | {{yes|by default}} |- | scope-local variable || {{No|no equivalent}} | set --local var |- | remove variable || unset var | set --erase var |- | check if a variable exists || test -v var | set --query var |- | array initialization || var=( a b c ) | <syntaxhighlight lang="fish"> set var a b c </syntaxhighlight> |rowspan=6| Every variable is an array |- | array iteration || <syntaxhighlight lang="bash"> for i in "${var[@]}"; do echo "$i" done </syntaxhighlight> || <syntaxhighlight lang="fish"> for i in $var echo $i end </syntaxhighlight> |- | argument vector:<br />all arguments || "$@" | $argv |- | argument vector:<br />indexing || "$1" | $argv[1] |- | argument vector:<br />length || $# | (count $argv) |- | argument vector:<br />shift || <syntaxhighlight lang="bash">shift</syntaxhighlight> | <syntaxhighlight lang="fish"> set --erase argv[1] </syntaxhighlight> |- | array representation in environment variables || <syntaxhighlight lang="bash">PATH="$PATH:$HOME/.local/bin"</syntaxhighlight> || <syntaxhighlight lang="fish">set PATH $PATH $HOME/.local/bin</syntaxhighlight> || fish assumes colon as array delimiter for translating variables to and from the environment. This aligns with many array-like environment variables, like $PATH and $LS_COLORS. |- | export and run || LANG=C.UTF-8 python3 | <syntaxhighlight lang="fish">env LANG=C.UTF-8 python3</syntaxhighlight> | <syntaxhighlight lang="bash" inline>env LANG=C.UTF-8 python3</syntaxhighlight> works in any shell, as env is a standalone program. |- | arithmetic || $((10/3)) || math '10/3' | <syntaxhighlight lang="bash" inline>expr 10 / 3</syntaxhighlight> works in any shell, as expr is a standalone program. |- | escape sequence || <syntaxhighlight lang="bash">$'\e'</syntaxhighlight> || \e | <syntaxhighlight lang="bash" inline>printf '\e'</syntaxhighlight> works in both shells; their <code>printf</code> builtins are both compatible with the GNU <code>printf</code> standalone program.<ref>{{cite web |last=Nordal |first=Andreas |date=11 July 2013 |title=printf does not support \e |url=https://github.com/fish-shell/fish-shell/issues/910 |access-date=24 March 2016 |website=fish issues}}</ref> |- | single quoted string:<br />escape sequences || <syntaxhighlight lang="bash"> 'mom'\''s final backslash: \' </syntaxhighlight> || <syntaxhighlight lang="python"> 'mom\'s final backslash: \\' </syntaxhighlight> || Bash only requires replacement of the single quote itself in single quoted strings, but the replacement is 4 characters long. The same replacement works in fish, but fish supports a regular escape sequence for this, thus requires escaping backslashes too (except permits single backslashes that don't precede another backslash or single quote). |}
==See also== {{Portal|Free and open-source software}} * Comparison of command shells * Unix
==References== {{Reflist|colwidth=35em|refs=
<ref name="bash_pitfalls">{{cite web |title=Bash Pitfalls |url=https://mywiki.wooledge.org/BashPitfalls |access-date=10 July 2016 |website=mywiki.wooledge.org |quote=This page shows common errors that Bash programmers make. (...) You will save yourself from many of these pitfalls if you simply always use quotes and never use word splitting for any reason! Word splitting is a broken legacy misfeature inherited from the Bourne shell that's stuck on by default if you don't quote expansions. The vast majority of pitfalls are in some way related to unquoted expansions, and the ensuing word splitting and globbing that result.}}</ref>
}}
== External links == * {{Official website}} – containing documentation and downloads * {{GitHub|fish-shell/fish-shell}} (active) * {{Cite web |title=fish |url=http://gitorious.org/fish-shell/ |url-status=dead |archive-url=https://web.archive.org/web/20110726104750/http://gitorious.org/fish-shell/ |archive-date=26 July 2011 |website=Gitorious}} (obsolete) * {{SourceForge | fish | fish}} (obsolete) * [https://lists.sourceforge.net/lists/listinfo/fish-users fish-users] – general discussion list for fish users * [https://github.com/fish-shell/fish-shell/wiki/Shell-Translation-Dictionary Shell Translation Dictionary] – another Bash/fish translation table
{{Unix Shells}}
{{DEFAULTSORT:Friendly Interactive Shell}} Category:Free software programmed in Rust Category:Scripting languages Category:Software using the GNU General Public License Category:Unix shells