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

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