Professional Documents
Culture Documents
Keys
Shortcut Description
Sample program
#!/usr/bin/env fish
Comments
1/7
# my comment
Printing text
read my_variable
Loops
Variables
Slicing
echo $my_variable[1..10]
echo $my_variable[2..]
echo $my_variable[..-2]
Numbers
Arithmetic
echo (math 1 + 2)
2/7
Operator Performs
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulo
^ Exponentiation
Strings
Matching
Pattern Matches
x? Zero or one x chars
[xy] x or y char
\w Word character
\d Digit character
Replacing
3/7
# Replaces the first match
string replace --regex 'Fish' 'fish' 'Hello from Fish!'
Conditionals
If/else
Comparisons
Numbers
-eq [Eq]ual
Strings
!= [N]ot [E]qual
Files
-d [D]irectory exists
4/7
File operator Meaning
Process communication
Writing to files
# Overwrite file
echo 'Hello from Fish!' > my_file
# Append to file
echo 'Hello from Fish!' >> my_file
Piping
my_command | another_command
Command substitution
The (...) expression is substituted with the output of the command inside it.
Process substitution
The (... | psub) expression is substituted with a temporary file with the command’s
output.
Functions
5/7
Events
Emitting
emit my_event
Event handling
Abbreviations
Completions
Defining completions
Option Description
--description Description
6/7
Declares the completion for a command.
Removing completions
Function Description
__fish_seen_argument Check whether the specified argument is used
7/7