You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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. ;)
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.
Activity
faho commentedon Oct 27, 2021
This is simply the top-level block. Imagine there's an implicit "begin; end" around everything you do.
EmilyGraceSeville7cf commentedon Oct 27, 2021
@faho, where I can find this note in docs?
faho commentedon Oct 27, 2021
It's not explicitly documented at the moment.
I'm not sure if it's necessary because
Maybe a small thing about "and implicitly at the top"?
EmilyGraceSeville7cf commentedon Oct 27, 2021
Yes, it would be great.
faho commentedon Oct 27, 2021
Ah, okay, no, you're quoting 3.3.0.
The current docs read:
So, since there's no function at the top level, they simply don't go out of scope.
CHANGELOG updates for 3.4.0