DasOhmoff San
DasOhmoff San

Reputation: 975

Vim use return value of executed bash command

I am trying to check if a line of code is in a file in vimscript. I need to use the return value of grep inside my if but I don't know hot get it.

This does not work of course:

if $(execute '!grep -q ' . shellescape(lineToAdd) . ' ' . shellescape(g:projectPath))
    echom "Already added."
    return
endif

Upvotes: 1

Views: 411

Answers (1)

Inian
Inian

Reputation: 85530

See v:shell_error as seen in this Vim documentation,

Result of the last shell command. When non-zero, the last shell command had an error. When zero, there was no problem. This only works when the shell returns the error code to Vim. The value -1 is often used when the command could not be executed. Read-only.

Upvotes: 1

Related Questions