Shell Translation Dictionary

Josh Cheek edited this page Oct 3, 2015 · 1 revision
Action/Thing Bash Fish Remarks
Command substitution "$(command)" (command) ...
Command substitution in a string "foo bar $(command)" "foo bar "(command) ...
Process substitution command <(command) command (command \\\| psub) ...
Logical AND between commands command1 && command2 command1; and command2 ...
Exit code of last command $? $status ...
Logical NOT ! command not command ...
PID of self $$ \%self ...
PID of last job $! \%last ...
Redirect STDERR command 2>/dev/null command ^/dev/null or command 2>/dev/null ...
Redirect STDERR command 2>&1 command 2>&1 ...
Redirect STDOUT command >/dev/null command >/dev/null ...
Run command in background command & command & ...
Run with environment variable VARIABLE=value command env VARIABLE=value command ...
Variable assignment foo=bar set foo bar By default bash variables are global, fish variables are function-scoped
Unset variable unset foo set -e foo ...
Check if a variable is defined [[ ${var+_} ]] or [[ -v var ]] (since bash 4.2) set -q foo ...
Check if a function is defined typeset -f function >/dev/null functions -q function ...
Export a variable export foo set -x foo $foo ...
Expand an n-element array/list to n arguments "${var[@]}" $var Bash does wordsplitting again on unquoted array, fish does not
Expand an n-element array/list to 1 argument "${var[*]}" "$var" ...
Remove element from array/list unset foo[1] set -e foo[2] ...
Count the number of elements in an array/list "${#var[@]}" count $var ...
Return the first array/list element "${var[0]}" or $var $var[1] Fish lists start from 1, bash arrays start from 0
if if CONDITION; then COMMAND; fi if CONDITION; COMMAND; end ...
for for VAR in LIST; do COMMAND; done for VAR in LIST; COMMAND; end ...
while while CONDITION; do COMMAND; done while CONDITION; COMMAND; end ...
Arguments to function $* or $@ $argv ...