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

How to get args passed after the script? #82

Closed
hustcer opened this issue Aug 2, 2021 · 4 comments
Closed

How to get args passed after the script? #82

hustcer opened this issue Aug 2, 2021 · 4 comments
Labels
question Further information is requested

Comments

@hustcer
Copy link
Contributor

hustcer commented Aug 2, 2021

If I ran try.sh foo in the console, I can get the foo input by $1.
And How to get args passed after the nu script?

nu try.nu foo bar

How can I get the param foo and bar ? Thanks.

@filaretov
Copy link
Contributor

Hey! It depends on what try.nu is doing.

The common scenario is probably defining a command in a Nu script, like this:

# try.nu

def say-hello [name] {
    echo $"Hello, ($name)!"
}

You can have multiple command arguments in the square brackets.

In order to use say-hello, you have to source try.nu and then the command will be available in the shell:

$ source try.nu
$ say-hello hustcer
Hello, hustcer!

If try.nu is a list of commands you want to run, I'm not sure how you could directly pass parameters from the command line.

Can you use a command definition like this for your use case and does this answer your question?

@fdncred fdncred added the question Further information is requested label Aug 5, 2021
@fdncred
Copy link
Collaborator

fdncred commented Aug 5, 2021

currently, i don't believe nushell supports passing multiple arguments on the nushell command line to scripts. i.e. nu some_script.nu param1 param2 param3 however, we do support custom commands, like @filaretov points out, and they can support multiple arguments. I'm closing with these answers. if we're missing what you're saying, please re-open.

@fdncred fdncred closed this as completed Aug 5, 2021
@hustcer
Copy link
Contributor Author

hustcer commented Aug 6, 2021

@fdncred @filaretov Thanks for your reply, source the script before run may help sometimes, but that's not enough: I wish I could run my scripts without sourcing, because the script may be called by npm run in a package.json file.
Maybe this reply express what I want.

@hustcer
Copy link
Contributor Author

hustcer commented Aug 6, 2021

And this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants