fbpx
Wikipedia

fish (Unix shell)

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.[4] Fish is considered an exotic shell since it does not rigorously adhere to POSIX shell standards, at the discretion of the maintainers.[5]

Fish
The fish shell. Its tagline, "fish - the friendly interactive shell", is displayed at the top.
Original author(s)Axel Liljencrantz
Developer(s)Fish-shell developers[1]
Initial release13 February 2005; 17 years ago (2005-02-13)
Stable release
3.6.0[2]  / 7 January 2023; 24 days ago (7 January 2023)
Repository
  • github.com/fish-shell/fish-shell
Written inC++
Operating systemUnix-like
TypeUnix shell
LicenseGPL-2.0-only[3]
Websitefishshell.com

Highlights

Fish has "search as you type" automatic suggestions based on history and current directory. This is essentially like Bash's 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 Tab ↹ for a tab completion instead. Tab-completion is feature-rich, expanding file paths (with wildcards and 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 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.[6]

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

# 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 

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 for the shell and then exit. 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 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

Version 2 adds:

  • Auto suggestions
  • 256 terminal colors
  • Web-based configuration
  • Improved performance (by having more bulletins ).

Bash/fish translation table

Feature Bash syntax fish syntax Comment
variable expansion:
with word splitting and glob interpretation
$var 

or

${var[@]} 

or

${var[*]} 
deliberately omitted Identified as a primary cause of bugs in posix compatible shell languages[8]
variable expansion:
scalar
"$var" 
deliberately omitted Every variable is an array
variable expansion:
array
"${var[@]}" 
$var 
Quoting 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 editor Ctrl+X,Ctrl+E Alt+E Upon invocation, moves line input to a text editor
evaluate line input Ctrl+Alt+E [9] Evaluates expressions in-place on the line editor
history completion Ctrl+R implicit
history substitution !! deliberately omitted Not 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 && echo FAIL || echo OK 
not command and echo FAIL or echo OK 
variable assignment
var=value 
set var value 
string processing:
replace
"${HOME/alice/bob}" 
string replace alice bob $HOME 
string processing:
remove prefix or suffix pattern, non-greedily or greedily
var=a.b.c "${var#*.}" #b.c "${var##*.}" #c "${var%.*}" #a.b "${var%%.*}" #a 
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 
export variable
export var 
set --export var 
Options discoverable via tab completion
function-local variable
local var 
by default
scope-local variable 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 ) 
set var a b c 
Every variable is an array
array iteration
for i in "${var[@]}"; do echo "$i" done 
for i in $var echo $i end 
argument vector:
all arguments
"$@" 
$argv 
argument vector:
indexing
"$1" 
$argv[1] 
argument vector:
length
$# 
(count $argv) 
argument vector:
shift
shift 
set --erase argv[1] 
array representation in environment variables
PATH="$PATH:$HOME/.local/bin" 
set PATH $PATH $HOME/.local/bin 
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 
env LANG=C.UTF-8 python3 
env 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' 
\e 
printf '\e' works in both shells; their printf builtins are both compatible with the GNU printf standalone program.[10]
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

References

  1. ^ "fish shell team members". GitHub.com. Retrieved 2021-07-28.
  2. ^ "Release 3.6.0". 7 January 2023. Retrieved 11 January 2023.
  3. ^ fishshell.com License for fish
  4. ^ Liljencrantz, Axel (2005-05-17). "Fish - A user-friendly shell". Linux Weekly News. Retrieved 2010-03-24.
  5. ^ "Fish docs: design". Retrieved 2021-04-09.
  6. ^ Linux.com. CLI Magic: Enhancing the shell with fish. Retrieved 2010-03-24.
  7. ^ Paul, Ryan (19 December 2005). "An in-depth look at fish: the friendly interactive shell". Ars Technica. Retrieved 10 March 2015. 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.
  8. ^ "Bash Pitfalls". Retrieved 2016-07-10. 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.
  9. ^ "RFC: Add binding to expand/evaluate tokens on commandline". GitHub. 2013-05-16. Retrieved 2021-04-09.
  10. ^ "printf does not support \e". fish issues. 11 Jul 2013. Retrieved 24 March 2016.

External links

  • Official website   – containing documentation and downloads
  • fish on GitHub (active)
  • on Gitorious (obsolete)
  • fish on SourceForge (obsolete)
  • Fish-users – general discussion list for fish users
  • Shell Translation Dictionary - another Bash/Fish translation table

fish, unix, shell, this, article, multiple, issues, please, help, improve, discuss, these, issues, talk, page, learn, when, remove, these, template, messages, this, article, needs, additional, citations, verification, please, help, improve, this, article, addi. This article has multiple issues Please help improve it or discuss these issues on the talk page Learn how and when to remove these template messages This article needs additional citations for verification Please help improve this article by adding citations to reliable sources Unsourced material may be challenged and removed Find sources Fish Unix shell news newspapers books scholar JSTOR May 2019 Learn how and when to remove this template message This article contains content that is written like an advertisement Please help improve it by removing promotional content and inappropriate external links and by adding encyclopedic content written from a neutral point of view March 2022 Learn how and when to remove this template message This article is missing information about Fish s history Please expand the article to include this information Further details may exist on the talk page March 2022 Learn how and when to remove this template message 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 4 Fish is considered an exotic shell since it does not rigorously adhere to POSIX shell standards at the discretion of the maintainers 5 FishThe fish shell Its tagline fish the friendly interactive shell is displayed at the top Original author s Axel LiljencrantzDeveloper s Fish shell developers 1 Initial release13 February 2005 17 years ago 2005 02 13 Stable release3 6 0 2 7 January 2023 24 days ago 7 January 2023 Repositorygithub wbr com wbr fish shell wbr fish shellWritten inC Operating systemUnix likeTypeUnix shellLicenseGPL 2 0 only 3 Websitefishshell wbr com Contents 1 Highlights 2 Syntax 2 1 No implicit subshell 2 1 1 Variable assignment example 3 Universal variables 4 Other features 5 Bash fish translation table 6 See also 7 References 8 External linksHighlights EditFish has search as you type automatic suggestions based on history and current directory This is essentially like Bash s 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 Tab for a tab completion instead Tab completion is feature rich expanding file paths with wildcards and 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 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 6 Syntax EditThe syntax resembles a POSIX compatible shell such as Bash but deviates in important ways where the creators believe the POSIX shell was badly designed 7 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 gt set foo bar gt 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 gt set wd pwd gt set wd pwd since version 3 4 gt echo wd Array variables A becomes an array with 5 values gt set A 3 5 7 9 12 Array slicing B becomes the first two elements of A gt set B A 1 2 gt echo B 3 5 You can index with other arrays and even command substitution output gt echo A seq 3 3 5 7 Erase the third and fifth elements of A gt set erase A B gt echo A 3 5 9 for loop convert jpegs to pngs gt for i in jpg convert i basename i jpg png end fish supports multi line history and editing Semicolons work like newlines gt 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 gt while read line set arr echo line tr n echo arr 5 end lt etc passwd String replacement replacing all i by I gt string replace a i I Wikipedia WIkIpedIa No implicit subshell Edit 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 for the shell and then exit 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 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 gt cat txt read line Variable assignment example Edit 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 lt 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 endUniversal variables EditFish 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 gt set universal EDITOR emacs This command will make the current working directory part of the fish prompt turn blue on all running fish instances gt set universal fish color cwd blueOther features EditAdvanced tab completion Syntax highlighting with extensive error checking Support for the X clipboard Smart terminal handling based on terminfo Searchable command history Version 2 adds Auto suggestions 256 terminal colors Web based configuration Improved performance by having more bulletins Bash fish translation table EditFeature Bash syntax fish syntax Commentvariable expansion with word splitting and glob interpretation var or var or var deliberately omitted Identified as a primary cause of bugs in posix compatible shell languages 8 variable expansion scalar var deliberately omitted Every variable is an arrayvariable expansion array var var Quoting 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 editor Ctrl X Ctrl E Alt E Upon invocation moves line input to a text editorevaluate line input Ctrl Alt E 9 Evaluates expressions in place on the line editorhistory completion Ctrl R implicithistory substitution deliberately omitted Not discoverableexplicit subshell expression fish c expressioncommand substitution expression expression or expression string collect process substitution lt expression expression psub Command not syntaxlogical operators cmd amp amp echo FAIL echo OK not command and echo FAIL or echo OKvariable assignment var value set var valuestring processing replace HOME alice bob string replace alice bob HOMEstring processing remove prefix or suffix pattern non greedily or greedily var a b c var b c var c var a b var a 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 aexport variable export var set export var Options discoverable via tab completionfunction local variable local var by defaultscope local variable no equivalent set local varremove variable unset var set erase varcheck if a variable exists test v var set query vararray initialization var a b c set var a b c Every variable is an arrayarray iteration for i in var do echo i done for i in var echo i endargument vector all arguments argvargument vector indexing 1 argv 1 argument vector length count argv argument vector shift shift set erase argv 1 array representation in environment variables PATH PATH HOME local bin set PATH PATH HOME local bin 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 env LANG C UTF 8 python3 env span class nv LANG span span class o span C UTF 8 python3 works in any shell as env is a standalone program arithmetic 10 3 math 10 3 expr span class m 10 span span class m 3 span works in any shell as expr is a standalone program escape sequence e e span class nb printf span span class s1 e span works in both shells their printf builtins are both compatible with the GNU printf standalone program 10 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 Edit Free and open source software portalComparison of command shellsReferences Edit fish shell team members GitHub com Retrieved 2021 07 28 Release 3 6 0 7 January 2023 Retrieved 11 January 2023 fishshell com License for fish Liljencrantz Axel 2005 05 17 Fish A user friendly shell Linux Weekly News Retrieved 2010 03 24 Fish docs design Retrieved 2021 04 09 Linux com CLI Magic Enhancing the shell with fish Retrieved 2010 03 24 Paul Ryan 19 December 2005 An in depth look at fish the friendly interactive shell Ars Technica Retrieved 10 March 2015 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 Bash Pitfalls Retrieved 2016 07 10 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 RFC Add binding to expand evaluate tokens on commandline GitHub 2013 05 16 Retrieved 2021 04 09 printf does not support e fish issues 11 Jul 2013 Retrieved 24 March 2016 External links EditOfficial website containing documentation and downloads fish on GitHub active fish on Gitorious obsolete fish on SourceForge obsolete Fish users general discussion list for fish users Shell Translation Dictionary another Bash Fish translation table Retrieved from https en wikipedia org w index php title Fish Unix shell amp oldid 1136644351, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.