Please enable JavaScript to use CodeHS

run.sh

This tutorial shows you how the `run.sh` file works in the CodeHS IDE.

By Zach Galant

Co-Founder of CodeHS

How to specify what will run when you hit the Run button

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

javac MyProgram.java && java MyProgram
javac Another.java && java Another
Bash

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.

Java Example

Python example

This also works in Python programs, so you can test that out here too.

Running bash commands

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.

Bash example