我有一个bash脚本,依赖于vim
至少是版本7.4
并且安装了python。我需要检查上面的条件是否匹配,如果不退出并要求用户更新他们的vim。从bash脚本检查vim版本和python支持
到目前为止,所有我能想到的是类似下面
has_vim = command -v vim >/dev/null
if ! $has_vim; then
echo "must have vim installed."
exit 1
fi
// Here I want do as the following pseudo code
vim_info = $(vim --version | grep python)
// suggest me if there is another way
vim_version = // find version info from $vim_info
has_python_support = // find python support from $vim_info
if ! $vim_version >= 7.4 && ! has_python_support; then
echo "vim version must be at least 7.4 and must be installed with python support"
fi
// everything is ok. carry on
目前,所有我能想到的是检查$vim_info
的预期VIM版本和Python的支持。
归结问题转化为有意义的句子:
如何检查Vim版本是大于或等于7.4,从bash脚本有Python支持?
如果你不想两次运行'vim --version':'vim --version | sed -n'1s/[^ 0-9] * \([0-9] [[0-9。] * \)。*/\ 1/p;/+ python/{s /.*/ python/p; q}' – andlrc