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, and does not adhere to
POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
shell standards by design.
Features
Fish displays
incremental suggestions as the user types, based on command history and the current directory. This functions similarly to
Bash's history search, but is always on, giving the user continuous feedback while typing commands. Fish also includes feature-rich
tab completion
Command-line completion (also tab completion) is a common feature of command-line interpreters, in which the program automatically fills in partially typed commands.
Command line interpreters are programs that allow a user to interact with the u ...
, with support for expanding file paths (with
wildcards and
brace expansion),
environment variables
An environment variable is a user-definable Value (computer science), value that can affect the way running process (computing), processes will behave on a computer. Environment variables are part of the environment in which a process runs. Fo ...
, and command-specific completions. Command-specific completions, including options with descriptions, can be to some extent generated from the commands'
man pages
A man page (short for manual page) is a form of software documentation found on Unix and Unix-like operating systems. Topics covered include programs, system libraries, system calls, and sometimes local system details. The local host administ ...
, but custom completions can also be included with software or written by users of the shell.
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
A web browser, often shortened to browser, is an application for accessing websites. When a user requests a web page from a particular website, the browser retrieves its files from a web server and then displays the page on the user's scr ...
.
Linux.com
CLI Magic: Enhancing the shell with fish. Retrieved 2010-03-24.
Syntax
The syntax resembles a POSIX
The Portable Operating System Interface (POSIX; ) is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines application programming interfaces (APIs), along with comm ...
compatible shell (such as Bash), but deviates in many ways
# 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 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 end < /etc/passwd
# String replacement (replacing all i by I)
> string replace -a "i" "I" "Wikipedia"
WIkIpedIa
No implicit subshell
Some language constructs, like pipelines
A pipeline is a system of pipes for long-distance transportation of a liquid or gas, typically to a market area for consumption. The latest data from 2014 gives a total of slightly less than of pipeline in 120 countries around the world. The Un ...
, functions and loops, have been implemented using so called subshells in other shell
Shell may refer to:
Architecture and design
* Shell (structure), a thin structure
** Concrete shell, a thin shell of concrete, usually with no interior columns or exterior buttresses
Science Biology
* Seashell, a hard outer layer of a marine ani ...
languages. Subshells are child programs that run a few commands in order 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.
# 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
Variable assignment example
This Bash example doesn't do what it seems: because the loop body is a subshell, the update to $found
is not persistent.
found=''
cat /etc/fstab , while read dev mnt rest; do
if test "$mnt" = "/"; then
found="$dev"
fi
done
Workaround:
found=''
while read dev mnt rest; do
if test "$mnt" = "/"; then
found="$dev"
fi
done < /etc/fstab
Fish example:
set found ''
cat /etc/fstab , while read dev mnt rest
if test "$mnt" = "/"
set found $dev
end
end
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.
# 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
Other features
* Advanced tab completion (with support for writing custom completions).
* Syntax highlighting
Syntax highlighting is a feature of text editors that is used for programming language, programming, scripting language, scripting, or markup language, markup languages, such as HTML. The feature displays text, especially source code, in differe ...
with extensive error checking.
* Support for the X clipboard
A clipboard is a thin, rigid writing board with a clip at the top for holding paper in place. A clipboard is typically used to support paper with one hand while writing on it with the other, especially when other writing surfaces are not avail ...
.
* Smart terminal handling based on terminfo
Terminfo is a library and database that enables programs to use display terminals in a device-independent manner. Mary Ann Horton implemented the first terminfo library in 1981–1982 as an improvement over termcap. The improvements include
* fas ...
.
* Searchable command history
Command history is a feature in many operating system shells, computer algebra programs, and other software that allows the user to recall, edit and rerun previous commands.
Command line history was added to Unix in Bill Joy's C shell of 1978; ...
.
* Web-based configuration
fish_config
.
Bash/fish translation table
See also
* Comparison of command shells
This article catalogs comparable aspects of notable operating system shell (computing), shells.
General characteristics
{, class="wikitable sortable sticky-header sort-under" style="width: auto; text-align: center; font-size: smaller;"
, -
...
* Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
References
External links
* – containing documentation and downloads
fish
on GitHub
GitHub () is a Proprietary software, proprietary developer platform that allows developers to create, store, manage, and share their code. It uses Git to provide distributed version control and GitHub itself provides access control, bug trackin ...
(active)
fish
on Gitorious
Gitorious was a free and open source web application for hosting collaborative free and open-source software development projects using Git revision control. Although it was freely available to be downloaded and installed, it was written primari ...
(obsolete)
fish
on SourceForge
SourceForge is a web service founded by Geoffrey B. Jeffery, Tim Perdue, and Drew Streib in November 1999. SourceForge provides a centralized software discovery platform, including an online platform for managing and hosting open-source soft ...
(obsolete)
Fish-users
– general discussion list for fish users
Shell Translation Dictionary
- another Bash/Fish translation table
{{DEFAULTSORT:Friendly Interactive Shell
Free software programmed in C
Scripting languages
Unix shells
Free software programmed in Rust