Skip to content
\n

Fine, I guess you want an argument list.

\n
$ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | each {run-external ($in | split row ' ')}\nError: nu::shell::eval_block_with_input\n\n  × Eval block failed with pipeline input\n   ╭─[entry #142:1:2]\n 1 │ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | each {run-external ($in | split row ' ')}\n   ·  ──────────┬──────────\n   ·            ╰── source value\n   ╰────\n\nError: nu::shell::cant_convert\n\n  × Can't convert to string.\n   ╭─[entry #142:1:69]\n 1 │ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | each {run-external ($in | split row ' ')}\n   ·                                                                     ──────────┬──────────\n   ·                                                                               ╰── can't convert list<string> to string
\n

This one through me through a loop, but I figured out it meant that run-external can't accept it as a list of strings. Annoying, but fine, quirk of the language.

\n
$ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | each {run-external ...($in | split row ' ')}\nError: nu::parser::missing_positional\n\n  × Missing required positional argument.\n   ╭─[entry #141:1:69]\n 1 │ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | each {run-external ...($in | split row ' ')}\n   ·                                                                     ▲\n   ·                                                                     ╰── missing command
\n

Fuck. Fine, I'll use a different approach.

\n
$ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | split column ' ' | each {run-external ...$in}\nError: nu::parser::missing_positional\n\n  × Missing required positional argument.\n   ╭─[entry #145:1:88]\n 1 │ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | split column ' ' | each {run-external ...$in}\n   ·                                                                                        ▲\n   ·                                                                                        ╰── missing command\n   ╰────\n  help: Usage: run-external <command> ...(args) . Use `--help` for more information.
\n

Are you serious? Okay, I guess it REALLY needs to be sure that it's not the one accepting a zero length list of arguments. quirk_of_the_language.jpeg

\n
$ [\"test -d /mnt/D/DCIM\", \"test -r /mnt/D/DCIM\"] | split column ' ' | each {run-external $in.column1 ...($in | values | skip 1 )}\n╭───┬──╮\n│ 0 │  │\n│ 1 │  │\n╰───┴──╯
\n

Finally! But oh god damnit, it won't let me use complete or access details of the command's output. I tried looking into the do command, but it doesn't let me 'ignore errors' while capturing their existence. I want to know about the errors, but I don't want them to propagate to my script.

\n

Side note: This is a quite convoluted way to achieve run-external's argument requirements. Is this really the way?

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Testing several directories with test (assuming test from coreutils) would look like this:

\n
# `src` and `assets` are two directories that exist in the folder I tested this in\n[src assets] | each { test -r $in -a -d $in | complete | get exit_code } | all { $in == 0 }\n# outputs `true`
\n
\n

My approach was this: Take multiple commands in strings

\n
\n

It goes against one of nushell's design principles: there's no eval in Nushell. No wonder it was hard to work it around.

","upvoteCount":3,"url":"https://github.com/nushell/nushell/discussions/14186#discussioncomment-11078152"}}}
Discussion options

You must be logged in to vote

Testing several directories with test (assuming test from coreutils) would look like this:

# `src` and `assets` are two directories that exist in the folder I tested this in
[src assets] | each { test -r $in -a -d $in | complete | get exit_code } | all { $in == 0 }
# outputs `true`

My approach was this: Take multiple commands in strings

It goes against one of nushell's design principles: there's no eval in Nushell. No wonder it was hard to work it around.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Xevion
Comment options

@weirdan
Comment options

Answer selected by Xevion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants