c05/c05_02
utterances-bot opened this issue · 2 comments
utterances-bot commented
5.2 os/exec 执行命令的五种姿势 — Go编程时光 1.0.0 documentation
zengguiyun commented
cmd2 := exec.Command("bash", "/home/wangbm/demo.sh")
请教一下,如果这个demo.sh有&、$这些特殊字符的话,能正常使用吗?
magicianlib commented
第二个通配符的问题可以使用 shell 的 -c
命令:
bash -c "ls -l /var/log/*.log"
对应的 go 代码为:
exec.Command("bash", "-c", "ls", "-l", "/var/log/*.log")
可以看下 bash 手册,对 -c
参数的解释如下:
-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
.