如何将 shell 变量定义为等于当前安装的 Vim 版本?

如何将 shell 变量定义为等于当前安装的 Vim 版本?

我打算编写一个 shell 脚本(如果需要具体信息,它将在 Zsh 中执行),它将通过运行确定最新的 Vim 补丁:

git pull origin master
vernew=$(git describe --tags | sed 's/^v//;s/-/./g')

使用 Vim git 存储库的本地副本,将其与我当前安装的 Vim 版本进行比较,如果两者不同,它将修改我在开放构建服务 (OBS) 中的规范文件中定义的补丁级别Vim 存储库。为了能够做到这一点,我需要知道如何将变量定义为等于当前安装的 Vim 版本。将其定义为:

verold=$(vim --version)

vim --version至少对我来说,跑步不是一个选择,返回:

VIM - Vi IMproved 7.4 (2013 Aug 10)
Included patches: 1-1304
Compiled by 'http://www.opensuse.org/'
Huge version without GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +tag_binary
+arabic          +file_in_path    +mouse_sgr       +tag_old_static
+autocmd         +find_in_path    -mouse_sysmouse  -tag_any_white
-balloon_eval    +float           +mouse_urxvt     -tcl
-browse          +folding         +mouse_xterm     +terminfo
++builtin_terms  -footer          +multi_byte      +termresponse
+byte_offset     +fork()          +multi_lang      +textobjects
+channel         +gettext         -mzscheme        +title
+cindent         -hangul_input    +netbeans_intg   -toolbar
+clientserver    +iconv           +path_extra      +user_commands
+clipboard       +insert_expand   +perl/dyn        +vertsplit
+cmdline_compl   +job             +persistent_undo +virtualedit
+cmdline_hist    +jumplist        +postscript      +visual
+cmdline_info    +keymap          +printer         +visualextra
+comments        +langmap         +profile         +viminfo
+conceal         +libcall         +python/dyn      +vreplace
+cryptv          +linebreak       +python3/dyn     +wildignore
+cscope          +lispindent      +quickfix        +wildmenu
+cursorbind      +listcmds        +reltime         +windows
+cursorshape     +localmap        +rightleft       +writebackup
+dialog_con      +lua/dyn         +ruby/dyn        +X11
+diff            +menu            +scrollbind      +xfontset
+digraphs        +mksession       +signs           -xim
-dnd             +modify_fname    +smartindent     +xsmp_interact
-ebcdic          +mouse           +sniff           +xterm_clipboard
+emacs_tags      -mouseshape      +startuptime     -xterm_save
+eval            +mouse_dec       +statusline      -xpm
+ex_extra        -mouse_gpm       -sun_workshop    
+extra_search    -mouse_jsbterm   +syntax          
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/current"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=1 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -Wall -pipe -fno-strict-aliasing      
Linking: gcc   -L. -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.22.0/x86_64-linux-thread-multi/CORE   -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXt -lX11 -lSM -lICE  -lm -lnsl    -ltinfo -lacl -lattr -ldl   -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.22.0/x86_64-linux-thread-multi/CORE  -L/usr/local/lib64 -fstack-protector-strong  -L/usr/lib/perl5/5.22.0/x86_64-linux-thread-multi/CORE -lperl -lm -ldl -lcrypt -lpthread  

该输出的第二行包含我感兴趣的内容,补丁级别。但我不知道如何定义verold等于补丁级别。完整版本(即 7.4.1304)也是一个可接受的verold值,如果您知道如何给我这个值。

答案1

verold=$(vim --version |sed -n 's/^Included patches:\s1-*//p')

相关内容