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
, as global with
, or local with
. 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.
Export a variable with
Store multiple strings in one variable with an array. Access an index:
for i in $PATH; echo $i is in the path; end
set smurf blue small
makes an array called smurf containing "blue" and "small".
Delete an element:
set -e smurf
Define a function like so:
ls -l $argv
Access arguments using
, call the function using
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
. You can put the suspended job in the background with
. Finally, you can list all running jobs with
Each command ends in either a newline or a semicolon. Chain commands using
command; and command2
command; or command2
check the previous command's exit status and act accordingly.
To define an alias, either make a function:
command ls --color=auto $argv
...or use use
alias NAME DEFINITION
which does this for you.