HOME

TheInfoList



OR:

fish is a Unix shell with a focus on interactivity and usability. Fish is designed to give the user features by default, rather than by configuration. Fish is considered an exotic shell since it does not rigorously adhere to POSIX shell standards, at the discretion of the maintainers.


Highlights

Fish has " search as you type" automatic suggestions based on history and current directory. This is essentially like Bash's 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 for a tab completion instead.
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 ...
is feature-rich, expanding file paths (with wildcards and
brace expansion Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. First released in 1989, it has been used as the default login shell for most Linux distributions. Bash was o ...
), variables, and many command specific completions. Command-specific completions, including options with descriptions, can to some extent be generated from the commands' man pages. Fish prefers features as commands rather than syntax. This makes features discoverable in terms of commands with options and help texts. Functions can also carry a human readable description. A special ''help'' command gives access to all the fish documentation in the user's web browser.Linux.com
CLI Magic: Enhancing the shell with fish. Retrieved 2010-03-24.


Syntax

The syntax resembles a POSIX compatible shell (such as Bash), but deviates in important ways where the creators believe the POSIX shell was badly designed. # Variable assignment, set the variable 'foo' to the # value 'bar'. Fish doesn't use the = operator, since # it is inherently whitespace sensitive. Also, the set # command easily 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 `` # since they can't be nested and look too much like ' '. > 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 # Semicolons work like newlines: > for i in *.jpg; convert $i (basename $i .jpg).png; end # but the multi-line form is comfortable to use because # fish supports multi-line history and editing. # 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, 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 ** Thin-shell structure Science Biology * Seashell, a hard o ...
languages. Subshells are simply child programs that run a few commands for the shell and then exit. Unfortunately, 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, which may surprise the user. Fish never forks off so-called subshells; all builtins are always fully functional. # 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 does not need a workaround: 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 allow 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. * Syntax highlighting with extensive error checking. * Support for the X clipboard. * Smart
terminal Terminal may refer to: Computing Hardware * Terminal (electronics), a device for joining electrical circuits together * Terminal (telecommunication), a device communicating over a line * Computer terminal, a set of primary input and output devi ...
handling based on terminfo. * 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; ...
. Version 2 adds: * Autosuggestions * 256 terminal colors * Web-based configuration * Improved performance (by having more builtins).


Bash/fish translation table


See also

* Comparison of command shells


References


External links

* – containing documentation and downloads
fish
on GitHub (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 (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