# How to translate bash to .bat

**URL:** <https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 25, 2022, 1:01pm UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652 "2022-05-25T13:01:41Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 25, 2022, 4:43pm UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652/21 "2022-05-25T16:43:53Z")

</div>

Well, but I cannot:

1. launch a Julia script just by typing its name
2. launch Julia with multiple threads from a script that runs on one thread

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 25, 2022, 4:47pm UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652/22 "2022-05-25T16:47:50Z")

</div>

> [@ufechner7](#):
>
> [I cannot] launch a Julia script just by typing its name

Sure you can. At least on Unix, you can put `#!/path/to/julia` at the top, exactly as you would with a shell script (to avoid having to do `bash foo.sh`).

Otherwise, you have to type `julia foo.jl`, but why is a few extra characters a big deal for a script like this?

> [@ufechner7](#):
>
> [I cannot] launch Julia with multiple threads from a script that runs on one thread

Sure you can. As I said above, you can launch additional `julia` processes from a Julia script, just as you would launch `julia` processes from a `bash` script.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 25, 2022, 4:51pm UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652/23 "2022-05-25T16:51:20Z")

</div>

> [@stevengj](#):
>
> Sure you can. At least on Unix, you can put `#!/path/to/julia` at the top, exactly as you would with a shell script (to avoid having to do `bash foo.sh` ).

Well, on Linux you can do that, but - as far as I know - not on Windows.  
Furthermore the path to Julia is system dependent, and if you want to write generic code I would not know what to put there.  
And as I said, it is not only about the script that creates a system image, but also about the script that launches julia and loads the correct system image…

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 25, 2022, 6:04pm UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652/24 "2022-05-25T18:04:28Z")

</div>

Created a feature request: [Julia should read a config file when launching · Issue #45455 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/45455)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 25, 2022, 9:54pm UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652/25 "2022-05-25T21:54:44Z")

</div>

> [@ufechner7](#):
>
> not on Windows.

Sure, on Windows you could instead write a one-line `foo.bat` script that runs `julia foo.jl`. A lot easier than porting a complicated shell script to `.bat` and maintaining both.

> [@ufechner7](#):
>
> Furthermore the path to Julia is system dependent, and if you want to write generic code I would not know what to put there.

Why is easier to find the path to a `.bat` or `.sh` script than a path to Julia? Why not just put `julia` in your path, or a link to Julia in the directory of your script, or…?

---

<div class="post-metadata">

**Author:** ![MA\_Laforge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ma_laforge/32/385_2.png) [@MA\_Laforge](https://discourse.julialang.org/u/MA_Laforge)\
**Post date:** [May 26, 2022, 1:43am UTC](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652/26 "2022-05-26T01:43:41Z")

</div>

### Registering a julia script file type/extension in Windows

Suggested here → [How to write a program as a Julia package? - #26 by MA\_Laforge](https://discourse.julialang.org/t/how-to-write-a-program-as-a-julia-package/80574/26)  
repo here → [GitHub - ma-laforge/JuliaScripting.jl](https://github.com/ma-laforge/JuliaScripting.jl)

In short, Windows allows you to register a file type, say `*.jl_script` to be executed with Julia in order to run. A sample file could be:

```julia-auto
#!JLScript -iq --startup-file=no --project=@SomeGlobalEnvironment
using ModuleFrom_SomeGlobalEnvironment

result = ModuleFrom_SomeGlobalEnvironment.run_important_tasks()
display(result)

:DONE

```

### Comments

- (Doesn’t actually need to use some global environment - but practical in terms of getting a stable Julia run environment)
- In the working example I provided, I pattern mach `#!JLScript` and pass the remaining arguments to the julia command.
- But if you want to be cross-compatible with how Linux shell scripts work, this could be changed to match some `#!/path/to/julia` pattern instead to match what @stevengj suggested to make julia scripts runnable on Unix/Linux.

### What already works

- Automatically loads the script using the desired, CLEAN, environment (starts with a clean `JULIA_LOAD_PATH` - see `install_files/launch_julia_script.ps1`.).
- Right now, my code \*auto-registers an “Excecute with Julia vX” Exprlorer menu item for the .jl\_script type (though I’m pretty certain I am using Win-XP Legacy registry settings).
- You can launch `.jl_script` files using RMB from explorer.

\*auto-registers: when you call `JuliaScripting.install()`

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/8/a8ba273da46ac397347c5aaa3ca675f4bdc8b4ad.png)

### What’s missing.

- Probably would be better to use newer methodology/registry settings if you are better at deciphering MS docs than I am.
- If you can figure out how to make this “Execute with Julia vX” item the default: then executing any `.jl_script` file from PowerShell or cmd will automatically run the script as intended.

Try it out for yourself: You can launch any `.txt` file from Windows PowerShell by typing in its the file name at the prompt. Doing so gets windows to figure out which “default program/action” to use to launch the `.txt` file.

[Previous page](https://discourse.julialang.org/t/how-to-translate-bash-to-bat/81652.md?page=1)
