如何使用管道命令创建屏幕

时间:2018-08-05 10:51:38

标签: bash gnu-screen gnu-parallel

我正在尝试使用管道打开命令的新屏幕。 我尝试了很多选择,例如:

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp();

const DialogflowApp = require('actions-on-google').DialogflowApp;

exports.receiveAssistantRequests = functions.https.onRequest((request, response) => {

const app = new DialogflowApp({request: request, response: response});

function handlerRequest(app) {

    const device = app.getArgument('devices');
    const status = app.getArgument('status');

    return admin.database().ref(`/automation/${device}/value`).set(status)
        .then(snapshot => { //I believe this is where the error is..
            app.ask(`Ok, switching ${device} ${status}. Do you want to control anything else?`);
        });

}
app.handleRequest(handlerRequest);
});

也许我缺少文件描述符之类的东西,但是搜索工作徒劳无功。 谢谢。

1 个答案:

答案 0 :(得分:1)

您不能在传递给{ code; }(或{{1})的参数中直接使用诸如;&|screen之类的shell语法结构}或parallel等)。 Shell将在运行命令之前尝试解析您的命令,因此任何类似

的内容
xargs

将使用命令echo | moo | echo解析为管道,并且什么都没有(当然这是语法错误)。如果要moo一对直立的竖线字符,则必须用引号引起来:

echo

如果要在外壳解析后在 之后对引用的内容进行评估,则有两个选项。

  • 将命令外部封装在脚本中,这样您就可以说echo '| moo |' 并在脚本文件screen myscript中包含实际有用的命令。 (某些有用的工具甚至允许您在此处使用shell函数或别名。)
  • 传递命令myscriptsh -c 'morecommands',以便引用该命令,但无论如何最终都会被执行。确实,这只是封装的另一种形式,但不需要单独的外部定义(如脚本文件或shell函数)。

因此,在您的示例中,您可以将代码放入类似bash -c 'morecommands'的脚本中,然后只需调用./metarunner;或像这样引用命令行

screen ./metarunner

(我在这里将screen sh -c "parallel --colsep '\t' -j 100 -m sh $HOME/runner.sh {} <$HOME/input" 切换为~,所以我可以使用$HOME而不是sh。如果您需要简单的Bash功能,或者懒得将代码重构为POSIX shell脚本显然使用bash而不是bash -c。另外,Difference between sh and bash的区别是什么。)

从切入点来说,我也摆脱了useless use of cat.

相关问题