I don't know if it's a bug or a feature, but here I get the following:
:echo (system('echo 1') == "1")
0
:echo (system('echo 1') == "1\000")
0
:echo (system('echo 1') == 1
1
:echo (system('echo 1 2 3') == 1
1
Note that in the latter two cases, Vim's string-to-integer conversion
steps in.
Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
43. You tell the kids they can't use the computer because "Daddy's got
work to
do" and you don't even have a job.
Oops: forgot to close the parens below
>
:echo (system('echo 1') == 1)
> 1
> :echo (system('echo 1 2 3') == 1
:echo (system('echo 1 2 3') == 1
> 1
>
> Note that in the latter two cases, Vim's string-to-integer conversion
> steps in.
>
>
> Best regards,
> Tony.
--
A non-vegetarian anti-abortionist is a contradiction in terms.
-- Phyllis Schlafly
Try
if l:r == "1\n"
I think it's :echoerr that is not displaying the \n in the string
correctly, but interpreting it as if it were \n in a buffer (which
stands in place of \0). If you just used :echo you would see 1 followed
by a blank line.
Ben.
--
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
As you've figured out, Vim's system() function includes in its
return value the newline at the end of the command's output. If you
need the result without the newline, use substitute() like this:
let x = substitute(system("some command"), "\n", "", "")
HTH,
Gary
> As you've figured out, Vim's system() function includes in its
> return value the newline at the end of the command's output. If you
> need the result without the newline, use substitute() like this:
>
> let x = substitute(system("some command"), "\n", "", "")
This will remove all newlines, not just at the end. If one knows that command
will output newline at the end, then he should just use system(...)[:-2].
Original message:
> This will remove all newlines, not just at the end.
No, it will remove the first newline, whether it's at the end or not.
> If one knows that command will output newline at the end, then he
> should just use system(...)[:-2].
Yes.
Or if you don't, use "\n$" as the pattern. Slower, but will only catch
an end-of-string newline and only if it exists.
Ben.
If a newline at the end is possible but not certain, and must be
removed, just use (untested)
substitute(system('foo bar baz'), '\n$', "", "")
where (IIUC)
\n (within single quotes) is passed unchanged to substitute() and
*then* interpreted by it as a linefeed
$ means end-of-string
Best regards,
Tony.
--
Stay away from flying saucers today.