miller
发布于

linux bash -c | sh -c

https://zhuanlan.zhihu.com/p/431138872

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

第一种是利用 "sh -c" 命令,它可以让 bash 将一个字串作为完整的命令来执行,这样就可以将 sudo 的影响范围扩展到整条命令。

$ sudo /bin/sh -c 'echo "hello" >> a.txt'

浏览 (466)
点赞
收藏
评论