Alias does not pass quoted parameters correctly to the external command (shell)
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
Can confirm. I compared this to how git aliases work and they do as you expected. Thanks for reporting!
This could probably be fixed by using shlex.quote, but I'm not sure that will work with Windows so well.
I can confirm the fix is working as expected on my setup as well. Thank you!