Pergunta

Does anybody know why this works with bash calculator (bc) in vim:

echo system ("echo 3+5 \| dos2unix \| bc -l") ---> output: 8   
echo system ("echo 3/5 \| dos2unix \| bc -l") ---> output: .600000000000000  
echo system ("echo 3*5 \| dos2unix \| bc -l") ---> output: 15   

but this not:

echo system ("echo 2^5 \| dos2unix \| bc -l") ---> output: 25  
echo system ("echo 3^5 \| dos2unix \| bc -l") ---> output: 35  

This is used under cygwin in Windows.

Foi útil?

Solução

What is the value of &shell option? It must be /path/to/cygwin/bash, not something ending with cmd.exe. The problem is that ^ is an escape character in windows cmd.exe, so echo 2^5 is somewhat equivalent to echo 2\5 resolving into echo 25.

If it is cmd.exe add a line

set shell=/path/to/cygwin/bash

to your vimrc.

Note though that echo 2^^^^5 resolving to echo 2^5 is somewhat strange (in plain cmd.exe it is echo 2^^5), but I saw very long discussion on vim-dev regarding escaping issues for cmd.exe some time ago, so it may be one of them. Should not happen on the most recent vim (or it is a bug).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top