-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Shell Translation Dictionary
Fabian Homborg edited this page Jul 7, 2021
·
8 revisions
| 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 or command1 && command2 (fish 3.0) |
... |
| Exit code of last command | $? |
$status |
... |
| Logical NOT | ! command |
not command or ! command (fish 3.0) |
... |
| PID of self | $$ |
$fish_pid |
previously %self (still available as of 3.3.1) |
| PID of last job | $! |
$last_pid |
previously %last
|
| Redirect STDERR | command 2>/dev/null |
command 2>/dev/null |
command ^/dev/null is disabled by default in 3.3.0, may still be reenabled using the future feature flag |
| 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 |
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 |
... |
| Function definition | fn_name() {...} |
function fn_name ... end |
... |
| Check if a function is defined | typeset -f function >/dev/null |
functions -q function |
... |
| Export a variable | export foo |
set -x foo $foo |
export compatibility function is available |
| 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 |
... |
| Parameter Expansion with default value | foo=${bar-word} |
set -q bar && set foo $bar || set foo word |
|
| Parameter Expansion with default value | foo=${bar:-word} |
test -n $bar && set foo $bar || set foo word |
- Wikipedia's Comparison of command shells
- Command Line Interpreters: POSIX Shell, Cmd.exe, PowerShell - Hyperpolyglot
- Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh - Hyperpolyglot
- Wikipedia's Command-line interpreter
- COMMAND.COM, SHELL and COMSPEC
- Wikipedia's Powershell - Comparison of cmdlets with similar commands
- Comparative Examples in MSH and KSH - PowerShell Team Blog
- Is Powershell really this bad? - Reddit. sysadmin
fish - The friendly interactive shell