Repository navigation
Description
Describe the bug
I believe it's currently impossible to do use the following pattern from bash type shells in nu:
<do things with given arguments, until reaching --, shifting away these arguments from the $@ list>
# Execute the command that's given after --
exec "$@"This allows for a nice continuation passing style of programming, this is sometimes called Bernstein chaining. After DJB who applied this in qmail (and other shell programs I believe).
This can work in nu when using run-external, for example:
def main [...command] {
run-external $command.0 ($command | skip 1)
}I would like for this to be possible with exec as well. I think for exec to be the most useful it would support the same signature as run-external, such that I could replace run-external for exec in the example above. For bonus points, add the -a name option from bash exec that sets the zeroth argument name in the execve() call.
Obviously this is a breaking change to the exec command. So I came up with four different solutions to this problem:
- Add
--execoption to therun-externalcommand when running on a unix system. This might be confusing in the docs for windows users. - Add
exec-externalor similar command which does what I want to do - Add a command that's similar to
applyfrom common lisp. This would execute arbitrary commands with a list of arguments, then you could do:apply exec $command. - Add syntax sugar for splatting arrays, like
@in oil, or*in python. Then you could doexec *$command
How to reproduce
- Try to execute a list of commands with
exec
Expected behavior
I can execute a list of command with exec
Screenshots
No response
Configuration
N/A
Additional context
Discussed briefly on discord: https://discord.com/channels/601130461678272522/614593951969574961/1093099484621328384
Activity
pingiun commentedon Apr 6, 2023
I would be willing to work on this, and I'm probably able to spend company time on it. Does the core team think it's a good idea?
fdncred commentedon Apr 6, 2023
I'd be up for your 3rd or 4th bullet. Let's see what other people think.
Just to be clear, this sound interesting to me
kubouch commentedon Apr 7, 2023
run-externalis more of an internal command that is not designed to be used in normal circumstances. We can changeexecto interpret list of values as args to the exec-ed command, similar to howrun-externalworks. I think that would be the simplest solution and it's something that can be done right away.The
applycommand would do basically a similar thing but in a more complicated way. It could be used to support more commands than justexecwhich makes it interesting, but it would need to solve the problem of passing flags around which is quite a broad issue. For the same reason, I wouldn't add any syntax sugar yet because. These would need to be designed a bit more carefully.pingiun commentedon Apr 9, 2023
I don't understand. Why not?
pingiun commentedon Apr 12, 2023
This seems to already work. Maybe it was added in the 0.78 release? I'm not sure but I will close the issue