javascript在浏览器中用的算是很泛滥了,但是有时候我们就想像其他语言一样脱离浏览器使用,windows上提供了运行javascript的脚本宿主,可以直接运行js文件;但是Linux用多了就希望什么事情都在Linux上实现,网上找了一下,还真有Linux上的js解释器,是mozilla提供的:
http://ftp.mozilla.org/pub/mozilla.org/js/
使用说明: https://developer.mozilla.org/en/SpiderMonkey_Build_Documentation
可以同时执行js文件和js语句,如:
js -f Y.js -e "print(Y);"
安装方法:
——————————–
1 |
<span style="color: rgb(102, 102, 102); font-style: italic;"># 安装。完成之后会有/usr/bin/js命令</span><br /><span style="color: rgb(194, 12, 185); font-weight: bold;">sudo</span> <span style="color: rgb(194, 12, 185); font-weight: bold;">apt-get</span> <span style="color: rgb(194, 12, 185); font-weight: bold;">install</span> spidermokey-bin<br /> <br /><span style="color: rgb(102, 102, 102); font-style: italic;"># 测试,执行命令</span><br />js <span style="color: rgb(102, 0, 51);">-e</span> <span style="color: rgb(255, 0, 0);">"var s='www.codigg.com';print(s.length);"</span><br /> <br /><span style="color: rgb(102, 102, 102); font-style: italic;"># 执行文件</span><br /><span style="color: rgb(122, 8, 116); font-weight: bold;">echo</span> <span style="color: rgb(255, 0, 0);">"var s='www.codigg.com';print(s.length);"</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">></span> test.js<br />js <span style="color: rgb(102, 0, 51);">-f</span> test.js<br /> <br /><span style="color: rgb(102, 102, 102); font-style: italic;"># 脚本和文件结合</span><br />js <span style="color: rgb(102, 0, 51);">-f</span> test.js <span style="color: rgb(102, 0, 51);">-e</span> <span style="color: rgb(255, 0, 0);">"print(100+s.length)"</span> |
——————————————————————————–
=============================================
1 |
<span style="color: rgb(194, 12, 185); font-weight: bold;">wget</span> http:<span style="color: rgb(0, 0, 0); font-weight: bold;">//</span>ftp.mozilla.org<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>pub<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>mozilla.org<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>js<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>js-1.8.0-rc1.tar.gz<br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">tar</span> <span style="color: rgb(102, 0, 51);">-xf</span> js-1.8.0-rc1.tar.gz<br /> <span style="color: rgb(122, 8, 116); font-weight: bold;">cd</span> js<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>src<br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">make</span> <span style="color: rgb(0, 120, 0);">BUILD_OPT</span>=<span style="color: rgb(0, 0, 0);">1</span> <span style="color: rgb(102, 0, 51);">-f</span> Makefile.ref<br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">mkdir</span> <span style="color: rgb(102, 0, 51);">-p</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>usr<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>include<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>smjs<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span><br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">cp</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">*</span>.<span style="color: rgb(122, 8, 116); font-weight: bold;">{</span>h,tbl<span style="color: rgb(122, 8, 116); font-weight: bold;">}</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>usr<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>include<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>smjs<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span><br /> <span style="color: rgb(122, 8, 116); font-weight: bold;">cd</span> Linux_All_DBG.OBJ<br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">cp</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">*</span>.h <span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>usr<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>include<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>smjs<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span><br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">mkdir</span> <span style="color: rgb(102, 0, 51);">-p</span> <span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>usr<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>local<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span><span style="color: rgb(122, 8, 116); font-weight: bold;">{</span>bin,lib<span style="color: rgb(122, 8, 116); font-weight: bold;">}</span><span style="color: rgb(0, 0, 0); font-weight: bold;">/</span><br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">cp</span> js <span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>usr<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>local<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>bin<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span><br /> <span style="color: rgb(194, 12, 185); font-weight: bold;">cp</span> libjs.so <span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>usr<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>local<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span>lib<span style="color: rgb(0, 0, 0); font-weight: bold;">/</span> |
=============================================