Skip to content

set -l works outside of command block #8385

Closed

Description

@EmilyGraceSeville7cf

Fish version: 3.3.0 (built from source)
OS version: Linux Mint 20.2 Cinnamon

Quote from docs:

Local variables are specific to the current fish session, and associated with a specific block of commands, and automatically erased when a specific block goes out of scope. A block of commands is a series of commands that begins with one of the commands for, while , if, function, begin or switch, and ends with the command end.

So why set -l works in the following code:

set -l var sample
echo $var # sample

?

What about to add note about it into docs or fix this behavior? I know that it's better to use -g in this case. ;)

Activity

  1. faho commented on Oct 27, 2021

    @faho
    Member

    This is simply the top-level block. Imagine there's an implicit "begin; end" around everything you do.

  2. EmilyGraceSeville7cf commented on Oct 27, 2021

    @EmilyGraceSeville7cf
    ContributorAuthor

    @faho, where I can find this note in docs?

  3. faho commented on Oct 27, 2021

    @faho
    Member

    It's not explicitly documented at the moment.

    I'm not sure if it's necessary because

    1. this paragraph is complicated enough as it is
    2. confusion here is rare

    Maybe a small thing about "and implicitly at the top"?

  4. EmilyGraceSeville7cf commented on Oct 27, 2021

    @EmilyGraceSeville7cf
    ContributorAuthor

    Yes, it would be great.

  5. faho commented on Oct 27, 2021

    @faho
    Member

    Ah, okay, no, you're quoting 3.3.0.

    The current docs read:

    Function variables are specific to the currently executing function. They are erased ("go out of scope") when the current function ends.

    Local variables are specific to the current block of commands, and automatically erased when a specific block goes out of scope. A block of commands is a series of commands that begins with one of the commands for, while , if, function, begin or switch, and ends with the command end. Outside of a block, this is the same as the function scope.

    So, since there's no function at the top level, they simply don't go out of scope.

  6. added
    docs
    and removed on Oct 27, 2021
  7. added this to the fish 3.4.0 milestone on Oct 27, 2021
  8. added a commit that references this issue on Dec 12, 2021
  9. locked as resolved and limited conversation to collaborators on Oct 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    docs

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions