问题
I would like to run some command in git-bash
shell via system()
or shell()
functions in R. I am on windows and the default shell is the command prompt. Is there any way I can switch the shell in system()
to git-bash
?
Thank you
回答1:
If your %PATH%
includes C:\Program Files (x86)\Git\bin\
, you should be able to system call:
bash --login -i -c "your command"
The OP JdeMello confirms in the comments:
Yup: Didn't have
C:\Program Files\Git\bin
inPATH
.For completion, we can add
Git\bin
to PATH inR
(if necessary):if(length(grep("(?i)Git//bin", Sys.getenv("PATH"))) == 0) Sys.setenv(PATH=paste0(Sys.getenv("PATH"),";C://Program Files//Git//bin"))
That worked for me.
来源:https://stackoverflow.com/questions/56069587/how-to-execute-git-bash-command-with-system-or-shell-in-r