nushell: Nu script files cannot accept the string `'('`, `'['`, or `"'"` as arguments.

Describe the bug

Nu script files cannot accept the string '(', '[', or "'" as arguments.

The commands below produce the same error:

~/dev/nushell> nu test.nu '('
Error: nu::parser::unexpected_eof

  × Unexpected end of code.
   ╭─[<commandline>:1:1]
 1 │ main (
   ╰────

~/dev/nushell> nu test.nu '['
Error: nu::parser::unexpected_eof

  × Unexpected end of code.
   ╭─[<commandline>:1:1]
 1 │ main [
   ╰────

~/dev/nushell> nu test.nu "'"
Error: nu::parser::unexpected_eof

  × Unexpected end of code.
   ╭─[<commandline>:1:1]
 1 │ main '
   ╰────

How to reproduce

  1. Create a script file using the following command: echo 'def main [a] { $a }' | save --force test.nu
  2. Execute the created script file with the string argument '(' as follows: nu test.nu '('

Expected behavior

For a script file like def main [a] { $a }, it should return the same character given, no matter what character is provided.

For example:

> echo 'def main [a] { $a }' | save --force test.nu
> nu test.nu '('
(

In the above case, when the string argument '(' is provided to the script, it should return '('.

Screenshots

No response

Configuration

key value
version 0.83.2
branch main
commit_hash c8f3799c20b5c30c3e798e71b81943acaf17246a
build_os macos-x86_64
build_target x86_64-apple-darwin
rust_version rustc 1.69.0 (84c898d65 2023-04-16)
rust_channel 1.69.0-x86_64-apple-darwin
cargo_version cargo 1.69.0 (6e9a83356 2023-04-12)
build_time 2023-08-07 12:14:48 +09:00
build_rust_channel release
allocator standard
features default, sqlite, trash, which, zip
installed_plugins

Additional context

No response

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 20 (4 by maintainers)

Most upvoted comments

@fdncred Thank you for considering my suggestion. I’m interested in helping out! However, I’m a bit concerned that the change might affect some scripts’ behavior without parameter types. So, I think I also need to write some changelog or documentation. I’m not very familiar with your project’s guidelines, so I might need to ask some questions along the way.

In addition, other metacharacters are also unacceptable, like bare =, strings containing | ; { } or beginning with $:

❯ ['=' 'a|b' 'a;b' 'a{b' 'a}b' '$a'] | each { nu test.nu $in }
Error: nu::parser::unknown_state

  × Unknown state.
   ╭─[<commandline>:1:1]
 1 │ main =
   · ───┬──
   ·    ╰── Incomplete statement
   ╰────

Error: nu::shell::external_command

  × External command failed
   ╭─[<commandline>:1:1]
 1 │ main a|b
   ·        ┬
   ·        ╰── executable was not found
   ╰────
  help: No such file or directory (os error 2)

Error: nu::shell::external_command

  × External command failed
   ╭─[<commandline>:1:1]
 1 │ main a;b
   ·        ┬
   ·        ╰── executable was not found
   ╰────
  help: No such file or directory (os error 2)

Error: nu::parser::unexpected_eof

  × Unexpected end of code.
   ╭─[<commandline>:1:1]
 1 │ main a{b
   ╰────

Error: nu::parser::unbalanced_delimiter

  × Unbalanced delimiter.
   ╭─[<commandline>:1:1]
 1 │ main a}b
   ·       ┬
   ·       ╰── unbalanced { and }
   ╰────

Error: nu::parser::variable_not_found

  × Variable not found.
   ╭─[<commandline>:1:1]
 1 │ main $a
   ·      ─┬
   ·       ╰── variable not found.
   ╰────

@amachang yes, you should wait until @jntrnr finishes the investigation. we’d hate for you to do a bunch of work and then we have to go a different direction.

Sounds good. Thanks for helping out.

thanks for investigating into this @amachang 🙏

@amtoine Thanks for linking another issue. I added it to my comment above.

might also be related to https://github.com/nushell/nushell/issues/9766 where i observe the quotes being removed before the arguments are passed to the script 🤔

which means "-a" becomes -a and is not a valid option in my issue and here "(" becomes ( and thus gives a syntax error 😕