e01.org

Fish (Unix shell)

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. Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.

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 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 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 string replace -a "i" "I" "Wikipedia" WIkIpedIa 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 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 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 with extensive error checking. Support for the X clipboard. Smart terminal handling based on terminfo. Searchable command history. Web-based configuration (fish_config). ==Bash/fish translation table== ==See also== Comparison of command shells Unix ==References==

source: e01 Encyclopedia · licence: CC BY-SA 4.0 · page · source revision

Cite this

"Fish (Unix shell)". 1778170170. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1353023091

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·