Skip to content

Programs spawned with 'exec' pass arguments to exec instead of the program #2675

Closed

Description

@kubouch

Describe the bug
In some cases, the exec command (which seems to be evoked internally) does not recognize arguments passed to the spawned program. Apparently, it thinks the arguments belong to exec and throws an error.

To Reproduce
Reproducible ONLY when nushell is a default login shell. When nu is launched from other default shell (e.g., bash) the issue does not appear.

I encountered this issue specifically under two circumstances:

  1. Using customized ssh commands from ~/.ssh/config
  2. Passing arguments to gdb --args

Steps to reproduce the behavior:

  1. Set nushell as the default login shell, log out and log back in.

  2. Put a ProxyCommand config into ~/.ssh/config, for example:

Host ServerUseX
    ProxyCommand ssh -XC [email protected]
  1. ssh ServerUseX
error: exec unexpected -XC
  ┌─ shell:1:12
  │
1 │ exec ssh -XC [email protected]
  │            ^ unexpected flag (try exec -h)
  1. ssh -XC [email protected]
    ... works fine
  2. gdb --args find ~ -name config.toml, type 'run', hit enter
error: exec unexpected -name
  ┌─ shell:1:38
  │
1 │ exec /usr/bin/find /home/user -name config.toml
  │                                   ^ unexpected flag (try exec -h)

Expected behavior
I expected the commands to run normally.

Configuration (please complete the following information):

  • OS (e.g. Windows): Arch Linux, 5.8.14-arch1-1
  • Nu version (you can use the version command to find out): 0.21.0, 2df8775
  • Optional features (if any): default, clipboard trash

Activity

  1. kubouch commented on Oct 16, 2020

    @kubouch
    ContributorAuthor

    When I type exec ls or exec 'ps aux' (as in the exec --help message), the nu exits. I'm not sure if that is intentional.

  2. fdncred commented on Oct 16, 2020

    @fdncred
    Contributor

    @kubouch I asked that question of @thegedge a while back. See it here in the PR.

  3. kubouch commented on Oct 16, 2020

    @kubouch
    ContributorAuthor

    OK so closing nu after exec is intended. This issue still persists though. I'm pretty sure it's just nushell passing the arguments to exec instead of the spawned process.

  4. changed the title [-]exec sometimes fails when running programs with arguments[/-] [+]Programs spawned with 'exec' pass arguments to exec instead of the program[/+] on Oct 31, 2020
  5. jakevossen5 commented on Mar 8, 2021

    @jakevossen5

    I can confirm that this is also an issue on macOS 11.2.2

  6. kubouch commented on May 1, 2021

    @kubouch
    ContributorAuthor

    OK, I looked into this and a partial solution is to wrap flag-like arguments into quotes, like this (excerpt from ~/.ssh/config):

    Host ServerUseX
        ProxyCommand ssh '-XC' [email protected]

    instead of

    Host ServerUseX
        ProxyCommand ssh -XC [email protected]

    Doesn't seem to work with gdb, though -- maybe it internally stripts the quotes or something like that.

    The core of the problem is that the programs spawn the commands with exec, assuming that every shell == POSIX shell. For example, when you run ssh ServerUseX, ssh spawns the following:

    exec ssh -XC [email protected]

    but then it finds nushell's exec which tries to interpret -XC as its flag.

    I think the best solution would be to add an option to tell the parser: "Just give me all args as strings and don't bother parsing them". I'm not sure yet whether it would be doable just by implementing a new SyntaxShape or by hard-coding it into the parser, I haven't looked at the parser code yet. @jonathandturner, what do you think about this? Perhaps I could take this as my first leap into the nushell's internals.

  7. fdncred commented on May 1, 2021

    @fdncred
    Contributor

    I noticed some weird quote handling with external the other day too related to #3363. I wonder if these things are related.

    #[cfg(not(windows))]
    {
    if !_is_literal {
    let escaped = escape_double_quotes(&arg);
    add_double_quotes(&escaped)
    } else {
    arg.as_ref().to_string()
    }
    }
    #[cfg(windows)]
    {
    if let Some(unquoted) = remove_quotes(&arg) {
    unquoted.to_string()
    } else {
    arg.as_ref().to_string()
    }
    }
    })
    .collect::<Vec<String>>();

  8. kubouch commented on May 1, 2021

    @kubouch
    ContributorAuthor

    I noticed some weird quote handling with external the other day too related to #3363. I wonder if these things are related.

    #[cfg(not(windows))]
    {
    if !_is_literal {
    let escaped = escape_double_quotes(&arg);
    add_double_quotes(&escaped)
    } else {
    arg.as_ref().to_string()
    }
    }
    #[cfg(windows)]
    {
    if let Some(unquoted) = remove_quotes(&arg) {
    unquoted.to_string()
    } else {
    arg.as_ref().to_string()
    }
    }
    })
    .collect::<Vec<String>>();

    Might be related, I wasn't even aware that nushell supports escapes. I tried escapes with the gdb command but it made some random output -- so the issue you linked might be related to that.

    I see the quotes as a workaround, though. Imagine if you don't have the option to modify the ssh proxy command, then you'd be screwed. I was thinking nushell could adopt some very very limited subset of POSIX behavior that some applications depend on, like exec in this case, to make life easier in certain specialized cases.

  9. fdncred commented on May 1, 2021

    @fdncred
    Contributor

    Nushell doesn't support escapes but since these are external commands, external commands support escapes, typically. That's my rationale.

  10. github-actions commented on Jun 24, 2021

    @github-actions

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

  11. kubouch commented on Jun 24, 2021

    @kubouch
    ContributorAuthor

    I don't have the issue on 0.33 anymore so I'll close it and we can reopen if somebody runs into it again.

  12. kubouch commented on Sep 15, 2021

    @kubouch
    ContributorAuthor

    Seems like people are stumbling on the "exec" issue from time to time. It works with the workaround wrapping the flag in quotes but sometimes this is not an option when using some 3rd party tool.

  13. added
    category:bug
    and removed on Sep 15, 2021
  14. kubouch commented on Oct 27, 2021

    @kubouch
    ContributorAuthor

    Similar issues: #3703 #4005

  15. RAOF commented on May 18, 2022

    @RAOF

    Seems like people are stumbling on the "exec" issue from time to time. It works with the workaround wrapping the flag in quotes but sometimes this is not an option when using some 3rd party tool.

    Particularly, there doesn't seem to be any way of getting gdb --args to call exec in a way that nushell is happy with, which is somewhat of a pain :)

  16. kubouch commented on May 18, 2022

    @kubouch
    ContributorAuthor

    @RAOF I managed to work around gdb by setting the SHELL environment variable to bash. In Nushell, you can do this, for example: with-env { SHELL: /bin/bash } { gdb --args program args... }

  17. dzintars commented on Nov 21, 2022

    @dzintars

    Encountered this as well.
    Solved via:

    Host hp
      # ProxyJump jump.host.com
      ProxyCommand ssh '-W' '[target.host.com]:22' jump.host.com

    Ideally i would like to avoid ProxyCommand and use default ProxyJump because it little bit complicates SSH config auto-generation in the pipelines.

  18. fdncred commented on Dec 22, 2022

    @fdncred
    Contributor

    closing as fixed by #7527. please re-open if it's not fixed.

  19. added this to the v0.74 milestone on Dec 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    category:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions