# Julia's shell mode can't recognize user-defined aliases of system commands on Linux

**URL:** https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724
**Category:** General Usage
**Tags:** question, shell, repl, linux
**Created:** [February 5, 2024, 5:55am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724 "2024-02-05T05:55:43Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [February 5, 2024, 5:55am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/1 "2024-02-05T05:55:43Z")

</div>

Why can’t Julia’s shell mode recognize user-defined aliases of system commands on Linux?

I defined some aliases in the `~/.bashrc` file such as

```shell
alias mydir="cd ~/path/to/my/directory/"

```

so that I can conveniently `cd` to my directory.

But in the Julia REPL when I typed `;` to enter the shell mode I found all the aliases I defined in the system `.bashrc` file no longer work.

What’s the reason? And how to make them work?

Thanks!

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [February 5, 2024, 6:26am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/2 "2024-02-05T06:26:42Z")

</div>

they don’t work because julia’s shell mode (just like it’s `run` command) doesn’t execute inside `bash`,  
It doesn’t execute in a shell at all.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [February 5, 2024, 6:29am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/3 "2024-02-05T06:29:32Z")

</div>

I don’t think there is any easy way to make them work.  
Especially for something which changes global state like `cd`.  
But I could be wrong there.

For some things you can get them to work by doing `bash -e mycommand` etc.  
This doesn’t work for `cd` since it runs in a seperate process with its own current directory.

Instead I suggest using a julia function  
`mydir() = cd(expanduser("~/path/to/my/directory/"))`  
which you can define in your `.juliarc`  
which you can just call in julia mode

---

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [February 5, 2024, 7:26am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/4 "2024-02-05T07:26:30Z")

</div>

Thanks! But how can I know which commands can work within Julia’s shell mode? I found I can even run `julia` again and again within an opened Julia’s shell mode if I have added its installation path to the environment variable in `.bashrc`. What is this feature and Julia’s shell mode designed for?

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [February 5, 2024, 9:00am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/5 "2024-02-05T09:00:09Z")

</div>

I think I had the same issue and fixed it by putting the following line in `.bash_profile`:

```julia
source .bashrc

```

Not sure it’s very elegant but it worked for me.  
My problem was getting Julia to see my global `mamba` installation for Python.

---

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [February 5, 2024, 9:18am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/6 "2024-02-05T09:18:07Z")

</div>

Thanks. Don’t know why it still didn’t work for me. 🫤

Do you mean I should define the aliases in `.bashrc` first and then add `source .bashrc` to `.bash_profile`? If so it didn’t work for me.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [February 5, 2024, 9:33am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/7 "2024-02-05T09:33:25Z")

</div>

> [@WuSiren](#):
>
> I found I can even run `julia` again and again within an opened Julia’s shell mode if I have added its installation path to the environment variable in `.bashrc`.

That’s because `julia` is an actual binary program that can be invoked, and the `julia` process you start from your shell inherits the environment variables currently set in your shell.

> [@WuSiren](#):
>
> What is this feature and Julia’s shell mode designed for?

Julias `shell>` prompt can only spawn processes - things like shell aliases are features of your particular shell (`bash`, `zsh`, etc), not of “spawning a process” in general. The same is true for other shell-builtins like `ulimit` or `export` in `bash`; they are not accessible to the `shell>` prompt because they’re not actual programs that can be invoked.

You can think of your shell as a sort-of mini programming language that’s interpreting space-separated commands as “spawn a process” or similar, so just like you can’t use `zsh` builtins in `bash`, you can’t use `bash` builtins (or aliases) in `shell>`.

---

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [February 5, 2024, 10:02am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/8 "2024-02-05T10:02:11Z")

</div>

Thanks for your explanation about its underlying mechanism. I seemed to understand. When I first learnt of the shell mode of Julia I thought I could do anything under Julia’s framework without having to exit it and now it seems I wanted too much.

---

<div class="post-metadata">

### Author: ![piechologist](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piechologist/32/27662_2.png) [@piechologist](https://discourse.julialang.org/u/piechologist)
#### Post date: [February 5, 2024, 8:11pm UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/9 "2024-02-05T20:11:14Z")

</div>

You could start any shell though. Occasionally, I run `shell> fish` to have access to my aliases, functions etc. without leaving the Julia REPL.

This starts a subshell (check `env` and you see SHLVL set to 2). You can exit that subshell with ^D to go back to the `shell>` mode.

Just be aware that any shell variables you set will be lost after exiting i.e., if you start `shell> bash`, set something like `important_var=42`, exit, and start `shell> bash` again, the variable will be gone.

---

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [February 6, 2024, 3:19am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/10 "2024-02-06T03:19:54Z")

</div>

Nice! 👍

---

<div class="post-metadata">

### Author: ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)
#### Post date: [February 6, 2024, 6:41am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/11 "2024-02-06T06:41:15Z")

</div>

For completeness, the thing I tested in the Julia REPL is access to environment variables (`$PATH`) defined in `.bash_profile`, and that worked. So it’s another issue than aliases

---

<div class="post-metadata">

### Author: ![WuSiren](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wusiren/32/42529_2.png) [@WuSiren](https://discourse.julialang.org/u/WuSiren)
#### Post date: [February 6, 2024, 6:47am UTC](https://discourse.julialang.org/t/julias-shell-mode-cant-recognize-user-defined-aliases-of-system-commands-on-linux/109724/12 "2024-02-06T06:47:32Z")

</div>

🤝 🤝
