function translate()
{
wd="`echo -n $1 | sed 's/ /%20/g'`"
if [ "$wd" = "" ];then
return 0
fi
tmp=/tmp/.fanyi.tmp
touch $tmp
curl --connect-timeout 4 -s -L http://dict.youdao.com/search?q=$wd -o $tmp
[ $? -ne 0 ] && rm -rf $tmp return 1
fy=`grep -E -A30 '<span class="pronounce">' $tmp`
vo=`sed -n 's#^.*<span class="phonetic">\(.*\)</span>.*#\1#gp' $tmp`
if [ "$vo" != "" ];then
echo $vo
fi
echo $fy | grep -E -o "<ul>.*</ul>" | sed -n 's#<ul>\|<li>\|</ul>\|</li>##gp'
rm -rf $tmp
}
export -f translate
vim实现自动翻译单词
最新推荐文章于 2020-12-20 04:36:56 发布