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

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?


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.


In addition to the hint of @GunnarFarneback: If you need the pass several arguments to your julia script, the ArgParse package is useful.

Hi! Thanks for the tips.
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 Script.jl Inputfile.h5

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

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

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:

#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))

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

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

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

In addition, you might want to use GitHub - dmolina/DaemonMode.jl: Client-Daemon workflow to run faster scripts in Julia 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 :wink:

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

1 Like

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