/bin/bash -c 的意思

背景

在看 kubernetes 的 yaml 配置文件时,发现很多执行 bash 命令的地方都会带上参数 -c,但是不知道这个参数的含义。

解答

-c 在 bash 手册中的解释:

-c string If the -c option is present, then commands are read from string.  If there are arguments after the string, they are assigned to the positional parameters, starting with $0.

也就是说,-c 命令表示后面的参数将会作为字符串读入作为执行的命令。

举个例子,尝试在本地执行下面两个命令:

  • /bin/bash -c ls
  • /bin/bash ls
执行结果

可以看到, /bin/bash -c 后面接 命令 ,而 /bin/bash 后面接 执行的脚本

相关资料

  • https://stackoverflow.com/questions/3985193/what-is-bin-sh-c

你可能感兴趣的:(/bin/bash -c 的意思)