How to Install, Configure and Run the Fish Shell
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Create a Linode account to try this guide with a $ credit .
This credit will be applied to any valid services used during your first days.
Fish, the Friendly Interactive Shell, is a replacement shell, which, out of the box, offers auto-suggestions; programmable completions based on installed man pages; a fully functional, readable, scripting language; and colored text support.
Install Fish
Install Fish using your distro’s package manager:
apt install fish
Start the Fish shell with the fish command:
root@localhost:~# fish Welcome to fish, the friendly interactive shell
Customize Fish
The configuration file for Fish is located at: ~/.config/fish/config.fish . You can write commands or Fish functions to this file. The fish_config command, will load a customization server on the browser:
Regarding Fish
Fish is similar to other shells: you type commands followed by arguments.
root@localhost ~# adduser Linode Adding user `Linode' . Adding new group `Linode' (1001) . Adding new user `Linode' (1001) with group `Linode' . Creating home directory `/home/Linode' .
However, in Fish, you chain commands with ; , instead of && :
root@localhost ~# mkdir FishDocs && cd FishDocs Unsupported use of '&&'. In fish, please use 'COMMAND; and COMMAND'. fish: mkdir FishDocs && cd FishDocs ^
If you can’t function without !! and && , check this repo out for a solution.
Use Fish
Fish boasts a full-featured scripting language. You can use scripts written in Fish to do anything you would do with a scripting language, and even some cooler things, like managing your anime/drama series.
Functions
Fish does not support aliasing. Instead Fish uses functions . Typing functions into Fish will output a list of functions that exist by default:
root@localhost ~/.c/fish# functions ., N_, abbr, alias, cd, contains_seq, delete-or-exit, dirh, dirs, down-or-search, eval, export, fish_config, fish_default_key_bindings, fish_indent, fish_mode_prompt, fish_prompt, fish_sigtrap_handler, fish_update_completions, fish_vi_cursor, fish_vi_key_bindings, fish_vi_mode, funced, funcsave, grep, help, history, hostname, isatty, la, ll, ls, man, math, mimedb, nextd, nextd-or-forward-word, open, popd, prevd, prevd-or-backward-word, prompt_pwd, psub, pushd, seq, setenv, sgrep, trap, type, umask, up-or-search, vared,
You can begin writing your own functions by using the syntax: functions name
You can write for loops on the fly with Fish:
You can learn more about Fish scripting in the official tutorial.
If you are a long time bash user, you may have accumulated an abundance of bash scripts, one-liners, and configurations that might make you reluctant to change shells. Fish-script is written differently than other scripting languages, but the built in bash -c command will run bash scripts from the Fish command line without hesitation.
For example, if you have a script that prints numbers 1-10:
for ((k=1; k
Using bash -c , you can take that same script as a string and run it without exiting Fish.
Next Steps
The best way to learn Fish is to use it. Fish is designed with The Law Of Discoverability in mind:
A program should be designed to make its features as easy as possible to discover for the user. Rationale: A program whose features are discoverable turns a new user into an expert in a shorter span of time, since the user will become an expert on the program simply by using it.
Follow the links in the More Information section to quickly explore the power and functionality of Fish.
More Information
You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.
- Fish Shell
- Fish Shell Tutorial
- Arch Wiki Fish Entry
- Fish Cookbook
This page was originally published on July 18, 2017.
Introduction¶
This is the documentation for fish, the friendly interactive shell.
A shell is a program that helps you operate your computer by starting other programs. fish offers a command-line interface focused on usability and interactive use.
Some of the special features of fish are:
- Extensive UI: Syntax highlighting , Autosuggestions , tab completion and selection lists that can be navigated and filtered.
- No configuration needed: fish is designed to be ready to use immediately, without requiring extensive configuration.
- Easy scripting: New functions can be added on the fly. The syntax is easy to learn and use.
This page explains how to install and set up fish and where to get more information.
Where to go?¶
If this is your first time using fish, see the tutorial .
If you are already familiar with other shells like bash and want to see the scripting differences, see Fish For Bash Users .
For a comprehensive overview of fish’s scripting language, see The Fish Language .
For information on using fish interactively, see Interactive use .
If you need to install fish first, read on, the rest of this document will tell you how to get, install and configure fish.
Installation¶
This section describes how to install, uninstall, start, and exit fish. It also explains how to make fish the default shell.
Installation¶
Up-to-date instructions for installing the latest version of fish are on the fish homepage.
To install the development version of fish, see the instructions on the project’s GitHub page.
Starting and Exiting¶
Once fish has been installed, open a terminal. If fish is not the default shell:
> fish
> exit
Default Shell¶
There are multiple ways to switch to fish (or any other shell) as your default.
The simplest method is to set your terminal emulator (eg GNOME Terminal, Apple’s Terminal.app, or Konsole) to start fish directly. See its configuration and set the program to start to /usr/local/bin/fish (if that’s where fish is installed - substitute another location as appropriate).
Alternatively, you can set fish as your login shell so that it will be started by all terminal logins, including SSH.
Setting fish as your login shell may cause issues, such as an incorrect PATH . Some operating systems, including a number of Linux distributions, require the login shell to be Bourne-compatible and to read configuration from /etc/profile . fish may not be suitable as a login shell on these systems.
To change your login shell to fish:
-
Add the shell to /etc/shells with:
> echo /usr/local/bin/fish | sudo tee -a /etc/shells
> chsh -s /usr/local/bin/fish
Again, substitute the path to fish for /usr/local/bin/fish - see command -s fish inside fish. To change it back to another shell, just substitute /usr/local/bin/fish with /bin/bash , /bin/tcsh or /bin/zsh as appropriate in the steps above.
Uninstalling¶
Shebang Line¶
Because shell scripts are written in many different languages, they need to carry information about which interpreter should be used to execute them. For this, they are expected to have a first line, the shebang line, which names the interpreter executable.
A script written in bash would need a first line like this:
#!/bin/bash
When the shell tells the kernel to execute the file, it will use the interpreter /bin/bash .
For a script written in another language, just replace /bin/bash with the interpreter for that language. For example: /usr/bin/python for a python script, or /usr/local/bin/fish for a fish script, if that is where you have them installed.
If you want to share your script with others, you might want to use env to allow for the interpreter to be installed in other locations. For example:
#!/usr/bin/env fish echo Hello from fish $version
This will call env , which then goes through PATH to find a program called “fish”. This makes it work, whether fish is installed in (for example) /usr/local/bin/fish , /usr/bin/fish , or ~/.local/bin/fish , as long as that directory is in PATH .
The shebang line is only used when scripts are executed without specifying the interpreter. For functions inside fish or when executing a script with fish /path/to/script , a shebang is not required (but it doesn’t hurt!).
When executing files without an interpreter, fish, like other shells, tries your system shell, typically /bin/sh . This is needed because some scripts are shipped without a shebang line.
Configuration¶
To store configuration write it to a file called ~/.config/fish/config.fish .
.fish scripts in ~/.config/fish/conf.d/ are also automatically executed before config.fish .
These files are read on the startup of every shell, whether interactive and/or if they’re login shells. Use status --is-interactive and status --is-login to do things only in interactive/login shells, respectively.
This is the short version; for a full explanation, like for sysadmins or integration for developers of other software, see Configuration files .
If you want to see what you changed over fish’s defaults, see fish_delta .
Examples:¶
To add ~/linux/bin to PATH variable when using a login shell, add this to ~/.config/fish/config.fish file:
if status --is-login set -gx PATH $PATH ~/linux/bin end
This is just an example; using fish_add_path e.g. fish_add_path ~/linux/bin which only adds the path if it isn’t included yet is easier.
To run commands on exit, use an event handler that is triggered by the exit of the shell:
function on_exit --on-event fish_exit echo fish is now exiting end
Resources¶
- The GitHub page
- The official Gitter channel
- The official mailing list at [email protected]
If you have an improvement for fish, you can submit it via the GitHub page.
Other help pages¶
- Introduction
- Frequently asked questions
- Interactive use
- The fish language
- Commands
- Fish for bash users
- Tutorial
- Writing your own completions
- Design
- Release notes
- License
Finally, a command
line shell for the 90s
fish is a smart and user-friendly command line
shell for Linux, macOS, and the rest of the family.
Autosuggestions
fish suggests commands as you type based on history and completions, just like a web browser. Watch out, Netscape Navigator 4.0!
Glorious VGA Color
fish supports 24 bit true color, the state of the art in terminal technology. Behold the monospaced rainbow.
Sensible Scripting
fish is fully scriptable, and its syntax is simple, clean, and consistent. You'll never write esac again.
Web Based Configuration
For those lucky few with a graphical computer, you can set your colors and view functions, variables, and history all from a web page.
Man Page Completions
Other shells support programmable completions, but only fish generates them automatically by parsing your installed man pages.
Works Out of the Box
fish will delight you with features like tab completions and syntax highlighting that just work, with nothing new to learn or configure.
Teach me to fish
Go fish
Homebrew
brew install fish
MacPorts
sudo port install fish
Installer
10.9+, Intel or Apple silicon
Installs to /usr/local/
App
fish.app bundles the fish shell with an AppleScript that launches it in Terminal.
Nothing is installed.
FreeBSD
NetBSD
OpenBSD
Cygwin
fish is available in setup,
in the Shells category.
Windows Subsystem for Linux
MSYS2
fish-3.6.1.tar.xz
cmake .; make; sudo make install
Git master
git clone https://github.com/fish-shell/fish-shell.git
cd fish-shell; cmake .; make; sudo make install
(Installation from the bleeding edge, for developers and advanced users.)
Release History
- 3.6.1, released March 25, 2023
- 3.6.0, released January 7, 2023 (tarball)
- 3.5.1, released July 20, 2022 (tarball)
- 3.5.0, released June 16, 2022 (tarball)
- 3.4.1, released March 25, 2022 (tarball)
- 3.4.0, released March 12, 2022 (tarball)
- 3.3.1, released July 6, 2021 (tarball)
- 3.3.0, released June 28, 2021 (tarball)
- 3.2.2, released April 7, 2021 (tarball)
- 3.2.1, released March 18, 2021 (tarball)
- 3.2.0, released March 1, 2021 (tarball)
- 3.1.2, released April 29, 2020 (tarball)
- 3.1.1, released April 27, 2020 (tarball)
- 3.1.0, released February 12, 2020 (tarball)
- 3.0.2, released February 19, 2019 (tarball)
- 3.0.1, released February 11, 2019 (tarball)
- 3.0.0, released December 28, 2018 (tarball)
- 2.7.1, released December 22, 2017 (tarball)
- 2.7.0, released November 23, 2017 (tarball)
- 2.6.0, released June 3, 2017 (tarball)
- 2.5.0, released February 3, 2017 (tarball)
- 2.4.0, released November 8, 2016 (tarball)
- 2.3.1, released July 3, 2016 (tarball)
- 2.3.0, released May 20, 2016 (tarball)
Development
fish development is hosted on GitHub. To clone the git repository:
git clone https://github.com/fish-shell/fish-shell.git
Build instructions are provided at the bottom of the GitHub page.
Need Help?
- matrix channel for quick questions
- Official fish mailing list
- Unix & Linux Stackexchange for questions.
- GitHub issues page for when you find a bug or have an awesome idea!
При подготовке материала использовались источники:
https://www.linode.com/docs/guides/how-to-install-configure-and-run-fish/
https://fishshell.com/docs/current/index.html
https://fishshell.com/