Variables
Three kinds: universal, global, and local. Universal variables are shared btw. all sessions on the computer per user. Global variables are specific to the current fish session, but they are outside of any block scope. Local variables are specific to a particular block scope and are automatically erased.
Set a variable as universal with
-U
, as global with
-g
, or local with
-l
. Scoping rules are as follows:
1. If a variable is explicitly set to either universal, global or local, that setting will be honored. If a variable of the same name exists in a different scope, that variable will not be changed.
2. If a variable is not explicitly set to be either universal, global or local, but has been previously defined, the variable scope is not changed.
3. If a variable is not explicitly set to be either universal, global or local and has never before been defined, the variable will be local to the currently executing function. Note that this is different from using the -l or –local flag. If one of those flags is used, the variable will be local to the most inner currently executing block, while without these the variable will be local to the function. If no function is executing, the variable will be global.
Exporting Variables
Export a variable with
-x
.
Arrays
Store multiple strings in one variable with an array. Access an index:
echo $PATH[3]
Iterate:
for i in $PATH; echo $i is in the path; end
Definition:
set smurf blue small
makes an array called smurf containing "blue" and "small".
Delete an element:
set -e smurf[1]
Functions
Define a function like so:
function ll
ls -l $argv
end
Access arguments using
$argv
, call the function using
ll
.
Jobs
When you execute a command, it starts a job. You can put a job in the background by adding the
&
suffix. You can suspend a currently running job using
Ctrl-Z
. You can put the suspended job in the background with
bg
. Finally, you can list all running jobs with
jobs
.
Chaining Commands
Each command ends in either a newline or a semicolon. Chain commands using
command; and command2
or
command; or command2
.
and
and
or
check the previous command's exit status and act accordingly.
Aliases
To define an alias, either make a function:
function ls
command ls --color=auto $argv
end
...or use use
alias NAME DEFINITION
which does this for you.
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets