# Calling a Julia script from the Linux terminal (with inputs)

**URL:** <https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380>\
**Category:** General Usage\
**Created:** [April 12, 2023, 8:27am UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380 "2023-04-12T08:27:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [April 12, 2023, 8:27am UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/1 "2023-04-12T08:27:54Z")

</div>

Hi all.  
I have a script that I need to run as a part of a shell script. Inside julia I can just put the name of the file, but in my workflow I need to parse this file name to the julia script (from a shelle script) and wait for julia to write some files so I can move them into folders.

So I am looking for something like this (inside the shell script).

julia Script.jl Inputfile.h5

Is there any way to do this?

Thanks

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 12, 2023, 8:34am UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/2 "2023-04-12T08:34:21Z")

</div>

I’m not really sure what the question is but `Inputfile.h5` will be available in `ARGS` as documented here: [Command-line Options · The Julia Language](https://docs.julialang.org/en/v1/manual/command-line-options/).

---

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [April 12, 2023, 10:11am UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/3 "2023-04-12T10:11:35Z")

</div>

In addition to the hint of @GunnarFarneback: If you need the pass several arguments to your julia script, the [ArgParse](https://carlobaldassi.github.io/ArgParse.jl/stable/) package is useful.

---

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [April 12, 2023, 12:35pm UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/4 "2023-04-12T12:35:37Z")

</div>

Hi! Thanks for the tips.  
But I do not understsand inside my script where arg1 goes.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 12, 2023, 12:46pm UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/5 "2023-04-12T12:46:10Z")

</div>

> [@marianoarnaiz](#):
>
> But I do not understsand inside my script where arg1 goes.

Can you share the relevant part from your julia code?

If you call julia like this

```julia
julia Script.jl Inputfile.h5

```

then you should have access to the input argument in this way

```julia
input_filename = ARGS[2]
# read(fn) etc

```

---

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [April 12, 2023, 12:50pm UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/6 "2023-04-12T12:50:03Z")

</div>

So. I have this function that reads my .h5 file, and to those inputs I apply some processes. Then make figures and save .jld2 files:

```julia
#Read data
strainrate, time, htime, offset, atrib = rdas("test/SR_DS_2023-04-11_13-54-42_UTC.h5");

# Cut the "bad" Channels from the DAS data.
slice_strainrate,slice_time,slice_htime,slice_offset = slicedas(strainrate,time,htime,offset; tmin=0, tmax=60, xmin=18, xmax=24);

# plot
c,viz = viewdas(strainrate, time, offset; cm=:RdBu_11, climit=(-1e4,1e4))
 save("HighF.png",viz.scene)

```

Nothing fancy, but I need to run this many times and I would like to input the .h5 file name from the terminal as arg1 and then run the rest. Then I can incorporate it into my bash scripts

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [April 12, 2023, 12:57pm UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/7 "2023-04-12T12:57:06Z")

</div>

In that case, it sound like you just need to put this line

```julia
strainrate, time, htime, offset, atrib = rdas(ARGS[2]);
#...
plot_fn = splitext(ARGS[2])[1] * ".png" # replace the ending for the output
save(plot_fn,viz.scene)

```

In addition, you might want to use [GitHub - dmolina/DaemonMode.jl: Client-Daemon workflow to run faster scripts in Julia](https://github.com/dmolina/DaemonMode.jl) to avoid the startup time. If that is relevant.

Other than that, it sounds like a task you could also do in pure Julia. But that’s of course your choice 😉

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 12, 2023, 2:10pm UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/8 "2023-04-12T14:10:46Z")

</div>

> [@SteffenPL](#):
>
> If you call julia like this
> 
> ```julia
> julia Script.jl Inputfile.h5
> 
> ```
> 
> then you should have access to the input argument in this way
> 
> `input_filename = ARGS[2]`

To nitpick this should be `ARGS[1]`. The name of the script is not included in `ARGS`.

---

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [April 12, 2023, 4:30pm UTC](https://discourse.julialang.org/t/calling-a-julia-script-from-the-linux-terminal-with-inputs/97380/9 "2023-04-12T16:30:40Z")

</div>

> [@SteffenPL](#):
>
> In addition, you might want to use [GitHub - dmolina/DaemonMode.jl: Client-Daemon workflow to run faster scripts in Julia](https://github.com/dmolina/DaemonMode.jl) to avoid the startup time. If that is relevant.

So good ideas. I will test tomorrow. Does the DaemonMode.jl works in one computer, I am not working on a server… just one computer that will run the script every minute for 24 months hahaha
