将nodejs文件变成可执行脚本
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