Fish (Unix shell): Difference between revisions

Content deleted Content added
m some mispelled words
Line 35:
 
<syntaxhighlight lang="fish">
# Variable assignment,
#
# setSet the variable 'foo' to the value 'bar'.
# value 'bar'. Fish doesn't use the = operator, sincewhich is inherently whitespace sensitive.
# commandThe easily'set' command extends to work with arrays, scoping, etc.
# it is inherently whitespace sensitive. Also, the set
 
# command easily extends to work with arrays, scoping, etc.
> set foo bar
> echo $foo
bar
# Command substitution, assign the output of the command
#
# 'pwd' into the variable 'wd'. Fish doesn't use ``
# sinceAssign theythe can'toutput beof nestedthe andcommand look'pwd' toointo muchthe likevariable ' wd'.
# Fish doesn't use backticks (``), which can't be nested and may be confused with single quotes (' ').
 
> set wd (pwd)
> set wd $(pwd) # since version 3.4
Line 70 ⟶ 74:
convert $i (basename $i .jpg).png
end
 
# fish supports multi-line history and editing.
# Semicolons work like newlines:
> for i in *.jpg; convert $i (basename $i .jpg).png; end
 
# but the multi-line form is comfortable to use because
 
# fish supports multi-line history and editing.
 
# while-loop, read lines /etc/passwd and output the fifth
Line 89 ⟶ 95:
 
=== No implicit subshell ===
Some language constructs, like [[pipeline (software)|pipelines]], [[subroutine|functions]] and [[control flow#Loops|loops]], have been implemented using so called subshells in other [[shell (computing)|shell]] languages. Subshells are simply child programs that run a few commands for the shell and then exit. Unfortunately, thisThis implementation detail typically has the side effect that any state changes made in the subshell, such as variable assignments, do not propagate to the main shell, which may surprise the user. Fish never forks off so-called subshells; all [[Shell_builtin|builtins]] are always fully functional.
<syntaxhighlight lang="fish">
# This will not work in many other shells, since the 'read' builtin