Hi,

I have been playing with shellescape() lately and I think I have found 
at least one bug with how shellescape() works and have one suggestion 
for :h shellescape() to make thinks clear.

Basically I wanted to execute printf "10,02d\n". So here is the script:

let a='printf "10,%02d\n" 1'
:exe '$r!'.shellescape(a,1)

I expected it to return 10,01. But it didn't. It returned this error:
bash: printf "10,%02d\n" 1: command not found

I believe it does this, because bash is trying to execute the command 
'printf "10,%02d\n"', which obviously does not exist. So apparently you 
have to shellescape each argument to the command separately, before 
executing the whole command, right?

Something like this, should work?

let a='find /tmp/files -type f -name "*" -print -exec chmod 764 {} ;'
exe ":!".join(map(split(a), 'shellescape(v:val,1)'), ' ')

If this is true, I think the documentation :h shellescape() should be 
updated, like this, to make that clear:

--- /home/chrisbra/local/share/vim/vim72/doc/eval.txt.old       2009-10-15 
21:15:03.000000000 +0200
+++ /home/chrisbra/local/share/vim/vim72/doc/eval.txt   2009-10-15 
22:19:45.000000000 +0200
@@ -5003,7 +5003,9 @@
                will enclose {string} in double quotes and double all double
                quotes within {string}.
                For other systems, it will enclose {string} in single quotes
-               and replace all "'" with "'\''".
+               and replace all "'" with "'\''". If you need to escape a
+               commandline consisting of several arguments, you have to
+               escape each argument separately.
                When the {special} argument is present and it's a non-zero
                Number or a non-empty String (|non-zero-arg|), then special
                items such as "!", "%", "#" and "<cword>" will be preceded by

And while we are at shellescape(), I think there is also this bug:

:exe ':r! printf '.shellescape("10%%")

which returns surprisingly:
,----
| 10/tmp/mutt-256bit-1004-14268-177/tmp/mutt-256bit-1004-14268-177
`----
instead of 10%.


Mit freundlichen Grüßen
Christian

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui