在kubectl中设置命令时'-/bin/sh -c ls'与'ls'之间的区别? [英] Difference between '-- /bin/sh -c ls' vs 'ls' when setting a command in kubectl?

查看:147
本文介绍了在kubectl中设置命令时'-/bin/sh -c ls'与'ls'之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对kubectl中的命令有些困惑.我不确定何时可以直接使用命令

命令:["command"]或-some_command

vs

命令:[/bin/sh,-c,命令"]或-//bin/sh -c some_command

解决方案

在较低级别上,每个(Unix/Linux)命令都作为一系列单词"被调用.如果您在外壳程序中键入命令,则外壳程序会进行一些预处理,然后创建"words".并运行命令.在Kubernetes的 command:(和 args:)中,不涉及外壳,除非您明确提供外壳.

除非您特别需要外壳功能,否则我将默认使用列表形式.

 命令:#覆盖Docker ENTRYPOINT- 命令--参数-  - 其他- 价值 

如果使用列表形式,则必须显式列出每个单词.您可以使用上面的YAML阻止列表语法或流列表语法 [command,arg1,arg2] .如果单个项目 [command,--option value] 中有嵌入的空格,则这些空格将包含在单个命令行选项中,就像您引用它一样,这经常会使程序感到困惑.

如果需要,可以显式调用shell.

 命令:-sh- -C-the_command-一个参数-另一个值 

此命令用正好三个词表示,分别是 sh ,选项 -c 和shell命令.Shell将以通常的方式处理该命令并执行.

仅当您执行的操作比运行带有固定参数的简单命令更复杂的操作时,才需要使用shell形式.运行多个顺序命令 c1&&c2 或环境变量扩展 c1"$ OPTION" 可能是最常见的,但是此处可以接受任何标准的Bourne shell语法(重定向,管道等)./p>

I am bit confused with commands in kubectl. I am not sure when I can use the commands directly like

command: ["command"] or -- some_command

vs

command: [/bin/sh, -c, "command"] or -- /bin/sh -c some_command

解决方案

At a low level, every (Unix/Linux) command is invoked as a series of "words". If you type a command into your shell, the shell does some preprocessing and then creates the "words" and runs the command. In Kubernetes command: (and args:) there isn't a shell involved, unless you explicitly supply one.

I would default to using the list form unless you specifically need shell features.

command: # overrides Docker ENTRYPOINT
  - the_command
  - --an-argument
  - --another
  - value

If you use list form, you must explicitly list out each word. You may use either YAML block list syntax as above or flow list syntax [command, arg1, arg2]. If there are embedded spaces in a single item [command, --option value] then those spaces are included in a single command-line option as if you quoted it, which frequently confuses programs.

You can explicitly invoke a shell if you need to:

command:
  - sh
  - -c
  - the_command --an-argument --another value

This command is in exactly three words, sh, the option -c, and the shell command. The shell will process this command in the usual way and execute it.

You need the shell form only if you're doing something more complicated than running a simple command with fixed arguments. Running multiple sequential commands c1 && c2 or environment variable expansion c1 "$OPTION" are probably the most common ones, but any standard Bourne shell syntax would be acceptable here (redirects, pipelines, ...).

这篇关于在kubectl中设置命令时'-/bin/sh -c ls'与'ls'之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆