5

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

JdeMello
  • 1,708
  • 15
  • 23
  • 1
    I'm not sure I understand. I'm on windows with git-bash, and `system('"/Program Files/Git/usr/bin/ls.exe"')` works without needing to change anything to specifically use git-bash. Perhaps you need to update your `PATH` env-var? What are you trying that is not working? – r2evans May 10 '19 at 01:52
  • My git credentials work fine in git-bash when using the terminal tab in RStudio (git-bash is my default shell in the Terminal tab). However, when I try `git clone git@github.com:someuser/somefolder` in `system()` it does not recognize my credentials. I understand I can set my credentials in command prompt too but I would like to not do it. – JdeMello May 10 '19 at 01:55

1 Answers1

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 in PATH.

For completion, we can add Git\bin to PATH in R (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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Yup. Didn't have `C:\Program Files\Git\bin` in `PATH`. For completion, we can add `Git\bin` to `PATH` in `R` (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. Thanks @VonC ! – JdeMello May 10 '19 at 13:17
  • @JdeMello Thank you for the feedback. I have included your comment in the answer for more visibility. – VonC May 10 '19 at 13:24