Can the Julia shell be changed to `/bin/bash`?

I’ve just learned that the Julia shell is not /bin/sh as I had assumed. It is it’s own thing, apparently.

Can the default shell be changed so that a /bin/bash shell is launched when the Shell Mode key ; is pressed?

I’m aware that I can run bash from the Julia Shell. But why press another 5 keys if you dont have to, right?

This is really an aside but -

I’m not quite sure what the intended purpose of the Julia Shell is. It doesn’t seem to make much sense to re-invent the wheel here - but I guess that’s another thread in itself, potentially. Someone can tell me if there’s an obvious reason why Julia has its own shell rather than using a native OS one, if there is a reason for it which I’ve overlooked.

I suppose it could. This IS by design, as I explained in the other answer, to be cross-platform. You can’t rely on e.g. bash installed, or any shell even sh; you might even run on a platform with no shell (all supported platforms have some shells, at least Windows with cmd, I mean just in theory some [future, e.g. a microcontroller] might have none available), i.e. no specific shell is preinstalled on all of Julia’s supported platforms. E.g. not bash on Windows (though by now with WSL2, wasn’t available when Julia was designed), and PowerShell not by default on Linux (but IS available there). Julia doesn’t want to bundle a shell (nor a terminal) with, making julia even larger, so it supports some common subset working on all platforms.

Note there is ReplMaker.jl that people have used to make their own modes (such as SQLREPL.jl that I nerdsniped into existence), in addition to ; for the default shell mode (I’m not sure it allows changing a specific mode, maybe it does, at least an improved mode could be prototyped with it).

Basically anything is possible in Julia, i.e. is dynamic, so you could even change the default shell [code to do anything, such as you ask for], to e.g. call bash, or PowerShell, such a package could even bundle either (or both!). I don’t know that anyone has done this, and you might not use that tool to do it, except to prototype at first.

It’s for quick ls, dir, etc. Note on Windows you have dir not ls (at least historically), and vice versa. I see I actually have dir also in Mint (and any Linux, e.g. Ubuntu) by now. If I recall Julia may support ls even when absent on Windows.

EDIT: I see dir does NOT actually work (or docs outdated? would with PowerShell?) on Windows (neither ls?):

For Windows users, Julia’s shell mode does not expose windows shell commands. Hence, this will fail:

I see some code specific for ~ on Unix/Linux and some Windows specific too:

Julia command literals (created with backticks) exist for a good reason. See Shelling Out Sucks and Put This In Your Pipe. TL;DR spawning a shell to spawn processes is more expensive and fragile than spawning the process directly.

The syntax for command literals is quite limited because ultimately Julia just creates a list of strings that are then passed to Libuv. Things like pipes, globs, && would have to be implemented in Julia itself because Libuv doesn’t handle them (there’s an issue about it, see Julia#20401).

Now, the REPL shell mode (entered with ;) has the same syntax as command literals but confusingly, it’s not always executed as a regular Cmd! The REPL will parse the command with Julia’s own syntax, but then it’ll call Base.repl_cmd, which will spawn a shell (except on Windows because :person_shrugging:). So the linked comment is sorta wrong.

Why does it work that way? I’ve got no idea… and I still find it really confusing.

EDIT: I see dir does NOT actually work (or docs outdated? would with PowerShell?) on Windows (neither ls?):

Yep. since the REPL doesn’t shell out on Windows, no built-in will work. You’d need an ls binary in your windows system for it to work.

2 Likes