schroot:传递要执行的命令,就像在 shell 中一样

发布于 2024-09-05 22:38:42 字数 364 浏览 5 评论 0原文

我想做类似的事情:

schroot -c name -u root "export A=3 && export B=4"

但我收到错误:

Failed to execute “export”: No such file or directory

换句话说,我希望能够在 schroot 环境。获得这种行为的正确方法是什么?

i want to do something like:

schroot -c name -u root "export A=3 && export B=4"

but I get the error:

Failed to execute “export”: No such file or directory

In other words, I want to be able to programmatically execute shell commands inside the schroot environment. What is the right way to get this behavior?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

满身野味 2024-09-12 22:38:42

我建议:

schroot -c name -u root sh -c "export A=3 && export B=4"

或者更好:

schroot -c name -u root -- sh -c "export A=3 && export B=4"

这会使用“-c”选项运行 shell,告诉它(shell)读取以下参数作为要执行的命令(脚本)。同样的技术适用于其他类似的命令:'su'、'nohup'、...

-- 选项终止 schroot 的参数,并确保命令行的其余部分将传递给 shell 并由 shell 解释,而不是由 schroot 进行解释。这是由 SR_注释,以及 schroot 的手册页 还建议也应该使用它(搜索“Separator”)。 GNU getopt() 函数默认会排列参数,这在这里是不需要的。 -- 阻止它排列 -- 之后的参数。

I recommend:

schroot -c name -u root sh -c "export A=3 && export B=4"

or better:

schroot -c name -u root -- sh -c "export A=3 && export B=4"

This runs the shell with the '-c' option telling it (the shell) to read the following argument as the command (script) to be executed. The same technique works with other analogous commands: 'su', 'nohup', ...

The -- option terminates the arguments to schroot and ensures that any options on the rest of the command line are passed to and interpreted by the shell, not by schroot. This was suggested by SR_ in a comment, and the man page for schroot also suggests it should be used too (search for 'Separator'). The GNU getopt() function by default permutes arguments, which is not wanted here. The -- prevents it from permuting the arguments after the --.

み格子的夏天 2024-09-12 22:38:42
schroot -c name -u root -- export A=3 && export B=4

确保 /etc/schroot/schroot.conf 具有

run-exec-scripts=true
run-setup-scripts=true
schroot -c name -u root -- export A=3 && export B=4

Ensuring that /etc/schroot/schroot.conf has

run-exec-scripts=true
run-setup-scripts=true
偏爱你一生 2024-09-12 22:38:42

你可以尝试一下

schroot -c name -u root "/bin/bash -c 'export A=3; export B=4'"

,但这是我第一次听说 schroot。并且导出看起来毫无用处......即使直接从命令行运行双引号的东西,子 shell 似乎也不想影响父 shell 的环境。

You could try

schroot -c name -u root "/bin/bash -c 'export A=3; export B=4'"

but this is the first time i've heard of schroot. And the exports look like they're useless...even running the double-quoted stuff directly from the command line, it seems the child shell doesn't want to affect the parent's environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文