Online Bash Shell Compiler
Write a shell script, press Run, and see the output. No Linux machine needed.
About this Bash compiler
This free online Bash compiler runs your shell script with Bash 5.2 on our server, inside a safe sandbox. When the script runs read, type the value in the terminal and press Enter. You see everything the script prints, and any error message from Bash with its line number.
It is made for students who learn shell scripting for a Unix or Linux lab, for an operating systems course, or for DevOps work, and who do not have a Linux computer at hand.
How to use it
- Write your script in the editor. A #!/bin/bash line at the top is allowed but not needed.
- If your script uses read, type the value in the terminal and press Enter. Print the question first with echo -n, because read -p does not show its question here.
- Press Run. The output and any error messages appear below.
Bash examples
Open any of these from the Examples tab in the side bar.
Hello, World
#!/bin/bash
name="DevHives"
echo "Hello, World!"
echo "Welcome to $name"
Read input and add
#!/bin/bash
read a
read b
sum=$(( a + b ))
echo "$a + $b = $sum"
Loop over an array
#!/bin/bash
fruits=("apple" "mango" "banana")
for fruit in "${fruits[@]}"; do
echo "I like $fruit"
done
echo "Total: ${#fruits[@]} fruits"
Function with if and else
#!/bin/bash
check_marks() {
if [ "$1" -ge 40 ]; then
echo "$1: pass"
else
echo "$1: fail"
fi
}
for m in 72 35 90; do
check_marks "$m"
done
What is Bash?
Bash is the shell on most Linux systems. A shell is the program that reads the commands you type in a terminal. A shell script is a text file with those commands in it, so you can run them again with one command.
Bash has variables, if and case, for and while loops, functions and arrays. System administrators and DevOps engineers use Bash scripts to automate their work, for example to back up files or to deploy an app. Strictly speaking Bash is an interpreter, not a compiler: it reads the script line by line and runs it.
Common errors and how to fix them
main.sh: line 3: name: command not foundThere is a space around the = sign. Write name="Asha", not name = "Asha".syntax error near unexpected token `fi'An if line is missing then, or the condition is missing spaces. Write if [ "$a" -gt 5 ]; then with a space after [ and before ].integer expression expectedA number test such as -gt got text or an empty value. Check that the variable holds a number, and put quotes around it.syntax error: operand expectedA number is missing inside $(( )). This happens when you write $b and b is empty — for example when you pressed Enter without typing a number.
Frequently asked questions
Which Bash version is used?
Bash 5.2. Arrays, associative arrays (declare -A), [[ ]] tests and $(( )) arithmetic all work.
Can I read input?
Yes. When the script waits at read, type in the terminal and press Enter. Show a question with echo -n "Name: " before read: read -p does not show its question here.
Can my script use the internet?
No. Scripts run in a sandbox with no network access, so commands such as curl, wget or ping cannot reach any website.
Are files kept between runs?
No. Each run starts in a new, empty sandbox. A file your script creates is deleted when the run ends.
Is there a time limit?
Yes. Without an account each run can use 3 seconds of computer time, and a script that is waiting for your input can wait up to 30 seconds. A free account gives more computer time.
Is this a real terminal?
No. You write the whole script first and then run it. You cannot type commands one by one while it runs.
Other free compilers
Learn to code with DevHives
Step-by-step lessons, DSA problems with a judge and mock interviews — made for students in India.
Create a free account