Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c05/c05_02 #57

Open
utterances-bot opened this issue Oct 10, 2022 · 2 comments
Open

c05/c05_02 #57

utterances-bot opened this issue Oct 10, 2022 · 2 comments

Comments

@utterances-bot
Copy link

5.2 os/exec 执行命令的五种姿势 — Go编程时光 1.0.0 documentation

https://golang.iswbm.com/c05/c05_02.html

Copy link

cmd2 := exec.Command("bash", "/home/wangbm/demo.sh")
请教一下,如果这个demo.sh有&、$这些特殊字符的话,能正常使用吗?

Copy link

第二个通配符的问题可以使用 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants