开发者

schroot: pass a command to be executed as if it’s in a shell

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?


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 --.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜