Fish (Unix shell): Difference between revisions

Content deleted Content added
m Made more encyclopedic.
document that fish was written in C++ in the past
 
(37 intermediate revisions by 24 users not shown)
Line 2:
{{Multiple issues|
{{More citations needed|date=May 2019}}
{{AdvertTone|date=MarchJuly 20222024}}
{{Missing information|Fish's history|date=March 2022}}
}}
{{lowercase}}
{{Infobox software
| name = Fish
| logo = Fish-shell-logo-ascii icon.svgpng
| screenshot = Fish shell 34.30.10 screenshot.pngwebp
| screenshot size = 300px
| caption = Version 4.0.0 of fish
| caption = The fish shell. Its tagline, "fish - the friendly interactive shell", is displayed at the top.
| author = Axel Liljencrantz
| developer = Fish-shell developers<ref>{{cite web| url = https://github.com/fish-shell?tab=members| title = fish shell team members | publisher = GitHub.com| date = | access-date = 2021-07-28}}</ref>
| released = {{release date and age|df=yes|2005|02|13|df=yes}}
| latest release version = {{wikidata|property|reference|edit|P348}}
| latest release date = {{Start date and age|{{wikidata|qualifier|P348|P577}}|df=yes}}
| programming language = [[Rust (programming language)|Rust]] since v4.0<ref>{{cite web |title=fish-shell 4.0b1, now in Rust |url=https://fishshell.com/blog/fish-4b/ |website=fishshell.com |access-date=18 December 2024}}</ref>, [[C++]] up to v3.7.1<ref>{{cite web |url=https://fishshell.com/docs/current/relnotes.html#fish-4-0-0-released-february-27-2025 |title=fish 4.0.0 (released February 27, 2025) |website=fishshell.com |access-date=2025-08-16}}</ref>
| programming language = [[C++]], [[Rust (programming language)|Rust]]
| operating system = [[Unix-like]]
| genre = [[Unix shell]]
Line 23 ⟶ 22:
| website = {{URL|http://fishshell.com}}
}}
'''fishFish''' ('''friendly interactive shell'''; stylized in lowercase) is a [[Unix shell|Unix-like shell]] with a focus on interactivity and usability. Fish is designed to givebe the user featuresfeature-rich by default, rather than byhighly configuration.configurable,<ref>{{cite web|url=https://lwn.net/Articles/136232|publisher=[[Linux Weekly News]]|title=Fish - A user-friendly shell|access-date=2010-03-24|date=2005-05-17|author=Liljencrantz, Axel}}</ref> Fish is considered an [[Unix shell#Other shells|exotic shell]] since itand does not adhere to [[POSIX]] shell standards, at the discretion of theby maintainersdesign.<ref>{{cite web|url=https://fishshell.com/docs/current/design.html|title=Fish docs: design|access-date=2021-04-09}}</ref>
 
==HighlightsFeatures==
Fish displays [[incremental search|incremental suggestions]] as the user types, based on command history and the current directory. This functions similarly to [[Bash (Unix shell)|Bash]]'s {{keypress|Ctrl|R}} history search, but is always on, giving the user continuous feedback while typing commands. Fish also includes feature-rich [[command-line completion|tab completion]], with support for expanding file paths (with [[wildcard character|wildcard]]s and [[Bash (Unix shell)#Brace expansion|brace expansion]]{{Broken anchor|date=2025-07-31|bot=User:Cewbot/log/20201008/configuration|target_link=Bash (Unix shell)#Brace expansion|reason=Anchor "Bash (Unix shell)#Brace expansion" links to a specific web page: "Brace expansion". The anchor (Brace expansion) [[Special:Diff/1303454031|has been deleted]].|diff_id=1303454031}}), [[Environment variable|environment variables]], and command-specific completions. Command-specific completions, including options with descriptions, can be to some extent generated from the commands' [[man page|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=2024-08-31 |website=fish shell}}</ref>
Fish has "[[incremental search|search as you type]]" [[Comparison of command shells#Automatic suggestions|automatic suggestions]] based on history and current directory.
This is essentially like Bash's {{keypress|Ctrl|R}} history search, but because it is always on instead of being a separate mode, the user gets continuous feedback while writing the command line, and can select suggestions with the arrow keys, or as in Bash, press {{keypress|tab}} for a tab completion instead. [[command-line completion|Tab-completion]] is feature-rich and has expanding file paths (with [[wildcard character|wildcard]]s and [[Bash (Unix shell)#Brace expansion|brace expansion]]), variables, and many command specific completions. Command-specific completions, including options with descriptions, can to some extent be generated from the commands' [[man page|man pages]].
 
The creator of Fish preferspreferred to add new features as commands rather than syntax. This makesmade features more [[Discoverability|discoverable]], as the built-in termsfeatures ofallow searching commands with options and help texts. [[Subroutine|Functions]] can also carry ainclude human readable descriptiondescriptions. A special ''help'' command gives access to all the fish documentation in the user's [[web browser]].<ref>[https://www.linux.com/news/cli-magic-enhancing-shell-fish Linux.com]. CLI Magic: Enhancing the shell with fish. Retrieved 2010-03-24.</ref>
 
==Syntax==
The syntax resembles a [[POSIX]] compatible shell (such as Bash), but deviates in importantmany ways where the creators believe the POSIX shell was badly designed.<ref name=indepthfish>{{cite web|last1=Paul|first1=Ryan|title=An in-depth look at fish: the friendly interactive shell|url=https://arstechnica.com/information-technology/2005/12/linux-20051218/2/|website=[[Ars Technica]]|date=19 December 2005 |access-date=10 March 2015|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">
Line 95 ⟶ 93:
 
=== No implicit subshell ===
Some language constructs, like [[pipeline (software)|pipelines]], [[subroutine|functions]] and [[control flow#Loops|loops]], have been implemented using so called [[Child process|subshells]] in other [[shell (computing)|shell]] languages. Subshells are child programs that run a few commands forin theorder shellto andperform 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 forkscreates offsubshells so-calledfor subshellslanguage features; all [[Shell_builtin|builtins]] arehappen alwayswithin fullythe functionalparent shell.
<syntaxhighlight lang="fish">
# This will not work in many other shells, since the 'read' builtin
Line 137 ⟶ 135:
 
==Universal variables==
Fish has a feature known as universal variables, which allowallows 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
Line 149 ⟶ 147:
 
==Other features==
* Advanced tab completion (with support for writing custom completions).
* [[Syntax highlighting]] with extensive error checking.
* Support for the [[X Window System|X]] [[Clipboard (software)|clipboard]].
* Smart [[Computer terminal|terminal]] handling based on [[terminfo]].
* Searchable [[command history]].
* Web-based configuration ([https://fishshell.com/docs/current/cmds/fish_config.html fish_config]).
 
==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 (programming)|glob]] interpretation ||
Line 336 ⟶ 334:
{{Portal|Free and open-source software}}
* [[Comparison of command shells]]
* [[Unix]]
 
==References==
{{Reflist|colwidth=50em35em|refs=
 
<ref name="bash_pitfalls">{{cite web|title=Bash Pitfalls|url=http://mywiki.wooledge.org/BashPitfalls|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.|access-date=2016-07-10}}</ref>
 
}}
Line 348 ⟶ 347:
*[https://github.com/fish-shell/fish-shell fish] on [[GitHub]] (active)
*[https://web.archive.org/web/20110726104750/http://gitorious.org/fish-shell/ fish] on [[Gitorious]] (obsolete)
*[httphttps://sourceforge.net/projects/fish/ fish] on [[SourceForge]] (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
Line 358 ⟶ 357:
[[Category:Scripting languages]]
[[Category:Unix shells]]
[[Category:Free software programmed in Rust]]