This tutorial shows you how the `run.sh` file works in the CodeHS IDE.
When you click the Run button in the CodeHS IDE, it runs the “main” file, which is signified by the play icon.
In Java programs, this is usually the MyProgram.java
file.
If you want to change the file that runs, one option is to add a new file called run.sh
The run.sh
file is a bash file that, if it exists, runs in place of the “main” file.
In this program below, we have our “main” file as MyProgram.java
and we also have another file named Another.java
Normally, the “main” file would run so we would see “Hello from MyProgram.java” printed to the screen.
The Another.java
file also has a main
method, so we’re also able to run that file directly if we wanted, so that’s what we’re specifying inside run.sh
run.sh
has the following contents
which, one after another, compiles and runs each of MyProgram.java
and then Another.java
Try running the code below to see what happens. You can make modifications to any of the files, including run.sh
to change what commands are executed when you click the Run button.
This also works in Python programs, so you can test that out here too.
Because run.sh
is just executing bash commands, you can even just run any bash script and do anything like modify the available files in the directory.