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 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 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.

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.

Syntax

The syntax resembles a POSIX compatible shell (such as Bash), but deviates in many ways

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.

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.

Workaround:

Fish example:

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.

Other features

Bash/fish translation table

FeatureBash syntaxfish syntaxComment
variable expansion: with word splitting and glob interpretation$var or ${var[@]} or ${var[*]}deliberately omittedIdentified as a primary cause of bugs in posix compatible shell languages
variable expansion: scalar"$var"deliberately omittedEvery variable is an array
variable expansion: array"${var[@]}"$varQuoting not necessary to suppress word splitting and glob interpretation. Instead, quoting signifies serialization.
variable expansion: as a space separated string"${var[*]}""$var"
edit line in text editorCtrl+X,Ctrl+EAlt+EUpon invocation, moves line input to a text editor
evaluate line inputCtrl+Alt+E—N/aEvaluates expressions in-place on the line editor
history completionCtrl+Rimplicit
history substitution!!deliberately omittedNot discoverable
explicit subshell(expression)fish -c expression
command substitution"$(expression)""$(expression)" or (expression | string collect)
process substitution<(expression)(expression | psub)Command, not syntax
logical operators!cmd&&echoFAIL||echoOKnot command and echo FAIL or echo OK
variable assignmentvar=valueset var value
string processing: replace"${HOME/alice/bob}"string replace alice bob $HOME
string processing: remove prefix or suffix pattern, non-greedily or greedilyvar=a.b.c "${var#*.}"#b.c "${var##*.}"#c "${var%.*}"#a.b "${var%%.*}"#astring 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
export variableexport varset --export varOptions discoverable via tab completion
function-local variablelocal varby default
scope-local variableno equivalentset --local var
remove variableunset varset --erase var
check if a variable existstest -v varset --query var
array initializationvar=( a b c )set var a b cEvery variable is an array
array iterationforiin"${var[@]}";do echo"$i" donefor i in $var echo $i end
argument vector: all arguments"$@"$argv
argument vector: indexing"$1"$argv[1]
argument vector: length$#(count $argv)
argument vector: shiftshiftset --erase argv[1]
array representation in environment variablesPATH="$PATH:$HOME/.local/bin"set PATH $PATH $HOME/.local/binfish 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 runLANG=C.UTF-8 python3env LANG=C.UTF-8 python3env LANG=C.UTF-8 python3 works in any shell, as env is a standalone program.
arithmetic$((10/3))math '10/3'expr 10 / 3 works in any shell, as expr is a standalone program.
escape sequence$'\e'\eprintf '\e' works in both shells; their printf builtins are both compatible with the GNU printf standalone program.
single quoted string: escape sequences'mom'\''s final backslash: \''mom\'s final backslash:\\'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

External links

  • – containing documentation and downloads
  • on GitHub (active)
  • . Gitorious. Archived from on 26 July 2011. (obsolete)
  • on SourceForge (obsolete)
  • – general discussion list for fish users
  • – another Bash/fish translation table