Skip to content

Nushell script call nu cannot parse empty string argument #9418

Closed

Description

@kai-tub

Describe the bug

An argument of a function with @string does not correctly parse empty strings when called directly via nu while it works for REPL and calling the function after source.

How to reproduce

When a script is called:

script.nu

def main [--arg: string] {
  print $arg
}

from bash or nu via

nu script.nu --arg ""
it returns

  × Missing flag argument.
   ╭─[<commandline>:1:1]
 1 │ main --arg
   ·      ───┬──
   ·         ╰── flag missing string argument
   ╰────

but it works when the function is created via REPL or sourced via source.

Expected behavior

I would expect the explicit nu script.nu call to behave like the interactive version.

Screenshots

No response

Configuration

key value
version 0.81.0
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.69.0 (84c898d65 2023-04-16) (built from a source tarball)
cargo_version cargo 1.69.0
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
features default, sqlite, trash, which, zip
installed_plugins

Additional context

No response

Activity

  1. added
    status:needs-triage
    on Jun 12, 2023
  2. fdncred commented on Jun 12, 2023

    @fdncred
    Contributor

    What's the use case for passing an argument with an empty string?

  3. kai-tub commented on Jun 12, 2023

    @kai-tub
    Author

    I am moving some parts of a bash script that makes heavy use of environment variables that might be unset.
    I would like to handle those empty values in the nu code directly.
    So the call inside of the bash script looks like: `nu script.nu --arg "$POSSIBLY_UNSET_ENV"

    There are also other variables that might be empty for similar reasons.
    And I prefer to not require "magic" environment variables within my nushell script although this is the current workaround :)

    So I guess my TL;DR is that it would be a quality of live improvement when calling nushell from bash scripts/cli.

  4. fdncred commented on Jun 12, 2023

    @fdncred
    Contributor

    Does this work for you? #9420

  5. removed
    status:needs-triage
    on Jun 12, 2023
  6. added a commit that references this issue on Jun 13, 2023
    30f4cc1
  7. added this to the v0.82.0 milestone on Jun 14, 2023
  8. kai-tub commented on Jun 30, 2023

    @kai-tub
    Author

    Ah, I forgot to reply. 😞

    Yes, it works exactly as how I expected it to work in v82! 🎉
    Thank you!

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions