将nodejs文件变成可执行脚本
 发布于 13 年前  作者 ironheart  10451 次预览  最后一次回复是 13 年前  来自  

chmod +x testsh.js testsh.js文件如下

#! /usr/local/bin/node
var command = [];
command.push('ls');
command.push('top');
var filterstring = process.argv[2] || '';
var filteredcommand = command;
filteredcommand = command.filter(
function( tmp ){

	return( tmp === filterstring );

}
);

if(filteredcommand.length > 0) {
console.log('i got command ' + filteredcommand);
}

运行 ./testsh.js ls