Skip to content

External command parameters get mangled #6399

Closed

Description

@panicbit

Describe the bug

External command paramaters get stripped of their outmost single quotes when their prefix contains an =.

How to reproduce

  • ^echo "= 'hi'"
  • ^echo "foo=bar 'hi'"

image

Expected behavior

I expect the parameters do behave the same as with non-external commands:

  • echo "= 'hi'"
  • echo "foo=bar 'hi'"

image

Configuration

key value
version 0.67.1
branch
commit_hash 0afe1e4
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.63.0 (4b91a6ea7 2022-08-08)
rust_channel stable-x86_64-unknown-linux-gnu
cargo_version cargo 1.63.0 (fd9c4297c 2022-07-01)
pkg_version 0.67.1
build_time 2022-08-24 11:35:06 +02:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins

Activity

  1. fdncred commented on Aug 24, 2022

    @fdncred
    Contributor

    I thought there was a PR a few weeks ago that stripped quotes like this on purpose?
    I think this is the one I'm thinking about #5846

  2. panicbit commented on Aug 24, 2022

    @panicbit
    ContributorAuthor

    I think the idea was to only strip it for flags, which I can understand somewhat, but I don't think stripping all quotes for any arg was the intention.

  3. panicbit commented on Aug 24, 2022

    @panicbit
    ContributorAuthor

    Maybe it's important to note that this issue affects a real life use case (in fact, one of my scripts at work broke due to the change):

    let dump_command = $"PGPASSWORD='($db_secret)' pg_dump -Fc -h '($db.host)' -p '($db.port)' -U postgres -d '($db.name)' > '/tmp/($dump_name)'"
    
    ^kubectl exec -n $bastion.namespace $bastion_pod -- sh -c $dump_command
  4. fdncred commented on Aug 24, 2022

    @fdncred
    Contributor

    I think the idea was to only strip it for flags, which I can understand somewhat, but I don't think stripping all quotes for any arg was the intention.

    Ya, you're probably right. Your issue just made me think of where we remove quotes and that was the only one I remember.

  5. fdncred commented on Aug 24, 2022

    @fdncred
    Contributor

    I'm not sure what changed to break your script. Feel free to look at PRs. Maybe it was a mistake or a bug.

    I've started using parameters like this because it seems to work better.

    ^external_command [$arg1 $arg2 $arg3]
    
  6. panicbit commented on Aug 24, 2022

    @panicbit
    ContributorAuthor

    In what ways does that work better? For the issue at hand at least it does not seem to matter:

    image

  7. fdncred commented on Aug 24, 2022

    @fdncred
    Contributor

    i guess i don't have anything that i call with parameters like this

  8. added
    A:external-commands
    A:quoting-expansion
    on Aug 25, 2022
  9. added this to the v0.68.0 milestone on Aug 26, 2022
  10. WindSoilder commented on Aug 26, 2022

    @WindSoilder
    Contributor

    @panicbit Would you please verify if the latest main works for you with the following example?

    let dump_command = $"PGPASSWORD='($db_secret)' pg_dump -Fc -h '($db.host)' -p '($db.port)' -U postgres -d '($db.name)' > '/tmp/($dump_name)'"
    
    ^kubectl exec -n $bastion.namespace $bastion_pod -- sh -c $""$dump_command""
  11. panicbit commented on Aug 26, 2022

    @panicbit
    ContributorAuthor

    It does work (although the correct incantation is $""($dump_command)""), but I'm not gonna lie, I hope this is not the final solution for this problem, because this feels pretty insane.
    Theoretically I would have to do $""arg"" with every parameter, just to make sure it doesn't get mangled.
    I will probably never complain about having to put quotes around variable uses in other shells anymore…

  12. WindSoilder commented on Aug 26, 2022

    @WindSoilder
    Contributor

    Yeah I agreed.

    Sorry for the current situation. I think it's better to use just $dump_command

  13. WindSoilder commented on Aug 27, 2022

    @WindSoilder
    Contributor

    @panicbit Hi, sorry for disturb, would you please check the latest main again?

    I think $dump_command can be used directly for now

    let dump_command = $"PGPASSWORD='($db_secret)' pg_dump -Fc -h '($db.host)' -p '($db.port)' -U postgres -d '($db.name)' > '/tmp/($dump_name)'"
    
    ^kubectl exec -n $bastion.namespace $bastion_pod -- sh -c $dump_command
    
  14. panicbit commented on Aug 27, 2022

    @panicbit
    ContributorAuthor

    It works 🥳. Thanks for caring about this and putting in all the effort! 😃

  15. added a commit that references this issue on May 23, 2024
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

    A:external-commandsA:quoting-expansion

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions