Skip to content

Alias does not pass quoted parameters correctly to the external command (shell) #2653

@otanner

Description

@otanner

Hi,

When using a shell function in aliases the parameters are not quoted correctly.

Here is a simple alias for testing (~/.aws/cli/alias):

[toplevel]

test-quotes =
  !f() {
    for i in "$@"; do
        echo "$i"
    done
  }; f

Testing the alias with aws test-quotes foo bar "foo bar":

Desired output:

foo
bar
foo bar

Actual output:

foo
bar
foo
bar

When debugging the ExternalAliasCommand's __call__ method the command_components variable contains ['f() {\nfor i in "$@"; do\necho "$i"\ndone\n}; f', 'foo', 'bar', 'foo bar'] so the quoted parameter with a space is parsed correctly on input.

However when making the actual function call the parameter is not quoted correctly: Using external alias 'test-quotes' with value: '!f() {\nfor i in "$@"; do\necho "$i"\ndone\n}; f' to run: 'f() {\nfor i in "$@"; do\necho "$i"\ndone\n}; f foo bar foo bar'

One fix could be to use quote function from https://pypi.python.org/pypi/shellescape (backport of Python shlex.quote for Python versions 2.x & < 3.3) for args to get arguments escaped correctly but this creates a new dependency. (something like command_components.extend(map(quote, args)))

Version info: CLI version: aws-cli/1.11.101 Python/2.7.13 Darwin/16.5.0 botocore/1.5.64

Metadata

Metadata

Labels

bugThis issue is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions