In vim, version 8.1, I need to use a shell command, not on a constant text, but containing a vim variable.
e.g. in Ex cmdline display by echo the difference in years from current date to a given date (hard coded 2000 - because I know no solution to apply the variable), reduced by 20.
let date_given_vim="1990-01-01"
exec '!echo $(( (date_given_sh="2000-01-01"; $(date "+\%Y") - $(date "+\%Y") --date="$date_given_sh") )) >/tmp/vim_aux'
let aux_a=join(readfile('/tmp/vim_aux'))
let aux_b=aux_a - 20
echo aux_b
In the shell command line the variable data_given_vim ought to be assigned to data_given_sh.
But I do not know how to accomplish this.
Also here another bad feature of vim is seen: the output of the !{cmd} cannot be assigned to a vim variable.
exewhy not simply add the variable in the command likeexe '!echo $( ' . date_vim . ') ...'? Also you are wrong about the output of a command not being assignable to a variable see here and there and finally How to export information from vim to bash which is probably a duplicate. – statox Apr 28 '21 at 08:25