ts

一个 调用 有道词典 在命令行里翻译单词的 linux shell 脚本

author: Hex Lee lihe757@gmail.com

1.添加此脚本到~/.bashrc的末尾

2.source ~/.bashrc

ts hello

你好

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  
#youdao
  
ts(){

curl -s
          
"http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top"
      
-d
      
"type=AUTO& i=$1&doctype=json&xmlVersion=1.4&keyfrom=fanyi.web&ue=UTF-8&typoResult=true&flag=false"
          
| sed -E -n 's/.\*tgt":"([^"]+)".\*entries":["","([^"]+)".*/1n 2/p';

return 0;
  
}
  
#sed -E -n 's/.\*tgt":"([^"]+)".*/1/p' ;
  
#sed -E -n 's/.\*tgt":"([^"]+)".\*entries":["","([^"]+)".*/1n 2/p';