Skip to content

New optional cell-path make use of variables harder #8480

@ghost

Description

Related problem

This is related to the merged unreleased MR 8379

Previous to this change i could do the following:

$ let b = "b"
$ {"a": 1} | get -i $b

With this change i cant find a way (expect for using a try-block) to do this:

$ let b = "b"
$ {"a": 1} | get $b?
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #3:1:1]
 1 │ {"a": 1} | get $b?
   ·                  ┬
   ·                  ╰── expected .
   ╰────

$ {"a": 1} | get ($b)?
Error: nu::parser::parse_mismatch

  × Parse mismatch during operation.
   ╭─[entry #5:1:1]
 1 │ {"a": 1} | get ($b)?
   ·                    ┬
   ·                    ╰── expected .
   ╰────

$ {"a": 1} | get $"($b)"?
Error: nu::shell::column_not_found

  × Cannot find column
   ╭─[entry #17:1:1]
 1 │ {"a": 1} | get $"($b)"?
   · ────┬───       ────┬───
   ·     │              ╰── cannot find column 'b"?'
   ·     ╰── value originates here
   ╰────

Describe the solution you'd like

I would appreciate it if one of the following would work:

  • get $b?
  • get ($b)?

Describe alternatives you've considered

{"a": 1} | try {get ($b)} catch {null} works, but is a bit chunky in my opinion.

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions