2017-08-15 17:49
浏览 104


According to run bash command in new shell and stay in new shell after this command executes, how can I run command:

bash --rcfile <(echo "export PS1='> ' && ls")

within golang? I've tried many combinations of exec.Command() but they did't work. For example:

exec.Command("bash", "--rcfile", `<("echo 'ls'")`)

I've also read this os, os/exec: using redirection symbol '<' '>' failed, but I think maybe my case is a bit more complicated.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongying195959
    dongying195959 2017-08-15 17:53

    You're almost there - I think the confusion is you're using piping to call bash, which means you actually need to call bash using bash:

    exec.Command("bash", "-c", `bash --rcfile <(echo "export PS1='> ' && ls")`)
    点赞 评论