On Fri, Jan 30, at 08:13 Tony Mechelynck wrote:
>
> On 30/01/09 07:52, WiggyWare wrote:
> > How would I save the results of an os call/script to a variable? I
> > would like to execute an os command in vimrc and assign the result to
> > a variable for use later in vimrc
> >
> > I've tried
> > let s:myvar = execute '! some os command'
> > but I get:
> > E121: Undefined variable: execute
> > E15: Invalid expression: execute '! ps -f | grep string_with_no_match'
> >
> > Thanks very much in advance!
>
> (untested)
>
> let s:myvar = system('ps -f | grep string_with_no_match')
>
While Tony's command is correct, you (the user) has to take measures for
the newline character. Watch this:
let name = system('whoami')
if name == 'ag' | echo 1 | else | echo 2 | endif
2
let name = substitute(system('whoami'), "\n", '', '')
if name == 'ag' | echo 1 | else | echo 2 | endif
1
Regards,
Ag.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---