In which shell Julia is running?

I have Julia code that executes external commands with parameters. The parameters are file or folder names. I thought if I check if the code is executed on Windows and use a backslash as path delimiter on Windows and a slash otherwise it would work. But it does NOT work if Julia is executed in a bash shell (git bash) on Windows.

How can I determine if Julia is executed in bash, powershell or on the dos command prompt on Windows?

Try using Base.Filesystem.joinpath, or if you need to do it manually Base.Filesystem.path_separator, maybe that already does the right thing.

I tried it, but it is not working correctly. On git bash on Windows I get:


which is wrong and doesn’t work…

Huh, that’s annoying. How about checking the contents of ENV["SHELL"]?

In git bash basename(ENV[“SHELL”]) is “bash.exe”. In powershell and on the command prompt this variable is undefined.

Not sure if I shall create a bug for Base.Filesystem.path_separator …

I guess you see two backslashes because the real and only one is masked. Try Base.Filesystem.path_separator == '\\' in the REPL.

According to the documentation:

  • The command is never run with a shell. Instead, Julia parses the command syntax directly, appropriately interpolating variables and splitting on words as the shell would, respecting shell quoting syntax. The command is run as julia’s immediate child process, using fork and exec calls.

Do your paths contain spaces or maybe other problematic characters?

Remember, git-bash is running on Windows, and so your are using Windows Julia. Which bypasses the Posix-emulation library (cygwin.dll?) used by bash, and adresses Windows native API. So you get Windows path separator … because that will be what Julia will use to find the files.

If you want to use bash Unix-like file path inside Julia, you will have to split them with “/” and then join the part with the (Windows) system separator (see joinpath)

Hope it helps,

1 Like

/ works just fine on Windows too as long as you use it consistently (i.e. don’t try to mix it with backslash).

@ufechner7 didn’t provide any example of the code they are trying to run, but my suspicion is that the problem is more due to incorrect argument quoting in run or something rather than simple issues with joinpath.

In any, case, @ufechner7 really should provide a MWE; it’s pointless to speculate about hypothetical bugs.

BTW, I use iscygwin()= Sys.iswindows() && haskey(ENV, "HOME") to know if I am running under Cygwin. You could try a similar function for git-bash?

1 Like