Skip to content

shell quoting broken #155

Description

@ezrizhu

try bash -c "echo a"
actually executes
bash -c echo a

Activity

  1. added
    bugSomething isn't working
    help wantedExtra attention is needed
    on Mar 31, 2024
  2. mgree commented on Apr 25, 2024

    @mgree
    Contributor

    The solution is to appropriately quote when we generate $script_to_execute. A basic version of this would not be too hard, but subtleties of escaping abound.

    Would be easily resolved in a rewrite not in the shell.

  3. mgree commented on Apr 25, 2024

    @mgree
    Contributor
    for arg in "$@"
    do
        case $arg in
            (*[$(printf " \n\t()<>&;|\`?*\$\"'")\\]*)
              quoted=$(echo "$arg" | sed -e "s/'/'\\\\''/")
              printf "'%s' " "$quoted";;
            (*)   printf "%s " "$arg";;
        esac
    done
    printf "\n"

    is a workable first cut.

  4. added a commit that references this issue on Apr 25, 2024
  5. mgree commented on Apr 26, 2024

    @mgree
    Contributor

    Our tests expect that try "echo hi>foo" will preserve the redirect and that try "echo hi; echo bye" will preserve the pair of commands.

    I don't see how we can support both this existing behavior and appropriate quoting of things like bash -c. An advantage of the current behavior is that you can run try "bash -c \"echo hi\"" and get the right behavior... whereas it's not clear how to preserve the shell syntax with this modified behavior.

    Unless you have a better idea, I'll delete the branch and close the issue.

  6. ezrizhu commented on Apr 26, 2024

    @ezrizhu
    MemberAuthor

    I don't have a better idea, feel free to delete the branch. I'll close the issue once the docs has been updated.

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

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions