BEGIN(1)
β¨ BEGIN(1) β¨
okay so bestie, this is a page from the fish-shell manual β literally the shell of all time π
πΈ NAME πΈ
begin β start a new block of code, no cap π«Ά
π SYNOPSIS π
begin; [COMMANDS ...]; end
{ [COMMANDS ...] }
π¦ DESCRIPTION π¦
begin is what you use to create a new block of code. iconic behavior honestly β¨
A block lets you do a few very slay things:
- introduce a new variable scope (peep the
<# variables-scope>section for the whole tea π) - redirect the input or output of a whole set of commands as a group
- specify precedence when you're using conditional commands like
and
The block is unconditionally executed β like, it does not ask questions, it does not check vibes, it just runs. begin; ...; end is equivalent to if true; ...; end.
begin does not change the current exit status itself. After the block has completed, $status will be set to the status returned by the most recent command. so like, don't blame begin, it's just the messenger π
Some other shells only support the { [COMMANDS ...] ; } notation. iykyk π
The -h or --help option displays help about using this command. always there for you fr fr π
π EXAMPLE π
The following code sets a number of variables inside of a block scope. Since the variables are set inside the block and have local scope, they will be automatically deleted when the block ends. gone, reduced to atoms, ghosted β¨
begin
set -l PIRATE Yarrr
...
end
echo $PIRATE
# This will not output anything, since the PIRATE variable
# went out of scope at the end of the block
In the following code, all output is redirected to the file out.html. the whole group's output, one file, main character energy π
begin
echo $xml_header
echo $html_header
if test -e $file
...
end
...
end > out.html
π Copyright π
fish-shell developers
ngl that's the whole page, bestie. go write some blocks and slay π
laterrr, and remember: this is fish-shell version 4.9, dated Sep 08, 2026 π¦β¨
π¦ where this page comes from
- arch rolling: fish 4.9.3-1 Β· GPL-2.0-only AND BSD-3-Clause AND ISC AND MIT AND PSF-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms