Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

scope variables for core

Output info on the variables in the current scope.

Signature

> scope variables {flags}

Input/output types:

inputoutput
nothingany

Examples

Show the variables in the current scope.

> scope variables

Notes

Lists variables that are available at runtime in the current stack and active overlays (locals and globals). Nested scopes such as do, if/for bodies, and custom commands include their locals while that scope is active; outer locals remain visible when the outer frame is still on the stack.

Closures only capture free variables that are referenced in the closure body. An outer local that is never mentioned is not captured, so after the defining scope ends it will not appear in scope variables when that closure runs. Mentioning the variable (for example $a) causes it to be captured and listed.

For example, this shows $a inside the do block, but not when the returned closure runs later:

do {
  let a = 123
  scope variables | where name == '$a' | print
  {|| scope variables | where name == '$a' }
} | let factory
do $factory

Adding a reference to $a in the closure body captures it so it appears:

{|| $a; scope variables | where name == '$a' }