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
  • Language Reference Guide
    • Readme
    • Types in the Nu Language
      • Basic Types
        • Any
        • Boolean
        • Integer
        • Float
        • Filesize
        • Duration
        • Datetime
        • Range
        • String
        • Record
        • List
        • Table
        • Closure
        • Nothing
        • Binary
        • Glob
        • Cell-Path
      • Other Data Types

        • Types that cannot be used to declare variables
          • Path
        • Types which are not declarable
          • Error
          • CustomValue
          • Block
      • Type signatures
      • Commands that interact with types
    • Operators
    • Flow control
      • if/else
      • loop
      • while
      • match
      • try/catch
      • break
      • return
      • continue
    • Filters
      • each and par-each
      • Filters to select subsets of data
      • where and filter
      • Understanding the difference between get and select
    • Custom Commands
    • Declarations
    • Variable Scope
    • Strings and Text Formatting
    • Helpers and debugging commands
    • Pipelines
    • MIME Types for Nushell

Path

Description:A string that will be expanded into a fully qualified pathname when passed to a command or closure
Annotation:path
Literal syntax:None
Casts:N/A (see below)

Additional Language Notes

  1. path is technically a "syntax shape" rather than a full "type". It is used for annotating strings that should be treated as a path to a filename or directory. ~ and . characters in the string will automatically be expanded treated as a path.

    Example:

    def show_difference [
     p: path
     s: string
    ] {
     print $"The path is expanded: ($p)"
     print $"The string is not: ($s)"
    }
    
    # Results
    cd ~/testing
    show_difference . .
    # => The path is expanded: /home/username/testing
    # => The string is not: .
    show_difference ~ ~
    # => The path is expanded: /home/username
    # => The string is not: ~
    
    # Multi-level directory traversal is also supported
    show_difference ... ...
    # => The path is expanded: /home/
    # => The string is not: ...
  2. The built-in syntax highlighting also treats strings and paths differently. Notice when typing the commands in the above example that, depending on your color configuration, the first and second argument will have different colorization.

Casts

There is no into path command, but several commands can be used to convert to and from a path:

  • path expand
  • path join
  • path parse

Common commands that can work with path

  • path (subcommands)
    • See: help path for a full list
  • Most filesystem commands (e.g., ls, rm)
    • See: help commands | where category == filesystem
Edit this page on GitHub
Contributors: NotTheDr01ds, fdncred