GolangCodingTime
GolangCodingTime copied to clipboard
c05/c05_02
cmd2 := exec.Command("bash", "/home/wangbm/demo.sh") 请教一下,如果这个demo.sh有&、$这些特殊字符的话,能正常使用吗?
第二个通配符的问题可以使用 shell 的 -c 命令:
bash -c "ls -l /var/log/*.log"
对应的 go 代码为:
exec.Command("bash", "-c", "ls", "-l", "/var/log/*.log")
可以看下 bash 手册,对 -c 参数的解释如下:
-cstring 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.