Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't seem to pass a string contains a "#" to a nushell script #6957

Closed
colemickens opened this issue Oct 31, 2022 · 7 comments
Closed

Can't seem to pass a string contains a "#" to a nushell script #6957

colemickens opened this issue Oct 31, 2022 · 7 comments
Labels
parser Issues related to parsing
Milestone

Comments

@colemickens
Copy link

Describe the bug

I can't seem to pass a string containing a pound sign ("#") to a nushell script:

cat minimal.nu

#!/usr/bin/env nu

def main [ f: string ] {
  echo $f
  echo $"($f)"
}
> /tmp/minimal.nu "hello#world"
hello
hello

> /tmp/minimal.nu "hello\#world"
hello
hello

> /tmp/minimal.nu 'hello\#world'
hello\#world
hello\#world

>/tmp/minimal.nu 'hello#world'
hello
hello

> let f = "hello#world"
/tmp/minimal.nu $f
hello
hello

I did try searching for other open issues, however, this one is hard to discover. I even know of #6741 but couldn't find it organically when searching Issues.

This seems more unexpected/bug-like than #6741 so I wanted to go ahead and open it.

How to reproduce

Try to pass a string containing a '#' to a nushell script, find that it is very difficult, or maybe impossible to do so without it being truncated.

Expected behavior

Some sort of workaround/quoting behavior, etc.

Screenshots

No response

Configuration

nu --version says 0.70.0 but I get it from the flake

Additional context

No response

@sholderbach sholderbach added the parser Issues related to parsing label Oct 31, 2022
@Decodetalkers
Copy link
Contributor

Decodetalkers commented Nov 1, 2022

Try

/tmp/minimal.nu '"hello#world"'

Emm , final out put then will be

"hello#world"

use signal quotation marks, because the args have quotation marks, then in nushell, it is turned to string, then the string received by nushell will from "ss#" -> ss#, Maybe there will be a good solution for such kind of thing

@hugosenari
Copy link

I have similar problem but with "a(b)c" it says executable was not found

echolino.nu

#!/nushell-0.70.0/bin/nu --stdin
def main [ p: string ] {
    echo $p
}

than from bash

 echolino "(ls)"

It list my files,

Curously if I add an space doesnt work

 echolino "(ls )"

@Kangaxx-0
Copy link
Contributor

To address this issue, please use string literal, something like " \' xxxxxx \' ", quotes do not work because std::env::args() does not reserve the quotes, the input "hello#world" will be converted into raw string hello#world, and the tokenization(LEX) will end up with incorrect state

@colemickens
Copy link
Author

Did this get fixed?

╭ zeph  ~/code/nixcfg 4.16s ✘1
╰─▶ nix build -v --rebuild .#pkgs.x86_64-linux.powertop
warning: Git tree '/home/cole/code/nixcfg' is dirty
warning: Git tree '/home/cole/code/nixcfg' is dirty
Using saved setting for 'experimental-features = nix-command flakes recursive-nix' from ~/.local/share/nix/trusted-settings.json.
Using saved setting for 'extra-substituters = https://cache.nixos.org https://colemickens.cachix.org https://nixpkgs-wayland.cachix.org https://unmatched.cachix.org https://nix-community.cachix.org' from ~/.local/share/nix/trusted-settings.json.
Using saved setting for 'extra-trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= colemickens.cachix.org-1:bNrJ6FfMREB4bd4BOjEN85Niu8VcPdQe4F4KxVsb/I4= nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA= unmatched.cachix.org-1:F8TWIP/hA2808FDABsayBCFjrmrz296+5CQaysosTTc= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=' from ~/.local/share/nix/trusted-settings.json.
checking outputs of '/nix/store/rhv9m7n1hjh8fh7v0kpz8y8g89n6fqp7-powertop-2.15.drv'..

I see the same behavior if I single/double quote it.

@colemickens
Copy link
Author

(to be clear, it appears fixed to me, but the PR didn't mention this issue. I'll leave this for a bit in case I'm confused, but I think this can probably be closed! Exciting!!)

@colemickens
Copy link
Author

And one last note, it also works passing it to a nushell script, which I think was part of my problem:

╭ zeph  ~/code/nixcfg 0.88s ✘1
╰─▶ ./main.nu build /home/cole/code/nixcfg#pkgs.x86_64-linux.nushell
▒▒ eval: /home/cole/code/nixcfg#pkgs.x86_64-linux.nushell

@sholderbach
Copy link
Member

sholderbach commented Mar 30, 2023

Thanks for checking back in on this issue @colemickens! I think you are correct that this was fixed (different PR to #7398)

Fixed in #8151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Issues related to parsing
Projects
None yet
Development

No branches or pull requests

6 participants