背景
在看 kubernetes 的 yaml 配置文件時,發(fā)現(xiàn)很多執(zhí)行 bash 命令的地方都會帶上參數(shù) -c,但是不知道這個參數(shù)的含義。
解答
-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 命令表示后面的參數(shù)將會作為字符串讀入作為執(zhí)行的命令。
舉個例子,嘗試在本地執(zhí)行下面兩個命令:
/bin/bash -c ls/bin/bash ls

執(zhí)行結(jié)果
可以看到, /bin/bash -c 后面接 命令 ,而 /bin/bash 后面接 執(zhí)行的腳本。