Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Linux shell执行javascript程序?_Javascript_Linux_Shell_Kernel_Rhino - Fatal编程技术网

如何从Linux shell执行javascript程序?

如何从Linux shell执行javascript程序?,javascript,linux,shell,kernel,rhino,Javascript,Linux,Shell,Kernel,Rhino,我想在不做第一行的情况下用执行javascript程序/bin/sh.#在javascript中不是注释字符。我也不想有一个.js扩展名 这可能吗?我记得读了很长一段时间关于一种使java程序在没有显式解释器的情况下运行的方法。然而,谷歌还没有推出。是的,只需调用rhino/path/to/your/js/file 如果您的路径中没有程序rhino,请将其替换为java org.mozilla.javascript.tools.shell.Main,您需要使用内核模块binfmt_misc。我没

我想在不做第一行的情况下用执行javascript程序/bin/sh.#在javascript中不是注释字符。我也不想有一个.js扩展名


这可能吗?我记得读了很长一段时间关于一种使java程序在没有显式解释器的情况下运行的方法。然而,谷歌还没有推出。

是的,只需调用
rhino/path/to/your/js/file


如果您的路径中没有程序
rhino
,请将其替换为
java org.mozilla.javascript.tools.shell.Main

,您需要使用内核模块
binfmt_misc
。我没有安装JS解释器,但我想Rhino的神奇之处在于:

# If it's not included in your kernel
sudo modprobe binfmt_misc
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc

# Register the .js extension as being run by Rhino
echo ':JSScript:E::js::/path/to/rhino:' > /proc/sys/fs/binfmt_misc/register
这假设您的脚本很乐意像这样运行:

 /path/to/rhino /path/to/your/script

如果需要将任何参数传递给Rhino,则需要设置一个包装器。
binfmt_misc
的完整文档是。

并且不要忘记使脚本可执行。因为我希望能够在不使用文件扩展名的情况下命名脚本,所以我还添加了:echo':javascript:M:/!::/usr/bin/js:'>/proc/sys/fs/binfmt_misc/register