Loading…

Online Bash Compiler and Playground

Browser-based compiler and playground for Bash, Progsity IDE.

About Bash

Bash is the shell on almost every Linux server, and the glue between programs: a few lines can read a file, filter it, count what is left and print a report. Learning it pays off the first time a task has to be repeated on a machine you reach over SSH.

This playground runs your script with real Bash on Linux, in a sandbox. The usual tools are on the path: the coreutils (sort, uniq, cut, tr, head, wc, seq), sed, grep, awk and bc. There is no network and nothing can be installed, so the script works with its stdin and the files it creates itself.

A syntax error is caught before the script starts, by the same check as bash -n, so a missing fi or done is reported once instead of halfway through a run.

How to use

  1. Write the script in the editor. A #!/bin/bash line is allowed and not needed.
  2. Put the input in the stdin panel and read it with read, or pipe it straight into a tool such as sort.
  3. Press Run. Standard output and standard error are shown in separate tabs.

FAQ

Which shell and version?›

GNU Bash 5.2, so arrays, [[ ]] tests, arithmetic with (( )) and parameter expansion all work. It is Bash, not plain sh.

Which commands are available?›

The GNU coreutils, sed, grep, awk (mawk), bc, and the other languages of this playground such as python3. Commands that need root or a network, like apt, curl to a website or sudo, will fail.

How do I do decimal arithmetic?›

Bash itself only knows integers. Pipe the expression to bc, for example echo "scale=4; 22 / 7" | bc.

Can a script create files?›

Yes, in its working directory, for the length of one run. Nothing is kept afterwards.

Is there a time limit?›

Yes. A run that loops forever is stopped and reported as a time limit, and the number of processes a script may start at once is capped.

Code examples

Tap “Try this” to load sample code into the editor above.

  • A loop with arithmetic

    for i in 1 2 3 4 5; do
      echo "$i squared is $((i * i))"
    done
  • Read two numbers

    read -r a b
    echo $((a + b))
  • Count repeated lines

    printf 'pear\napple\nmango\napple\n' | sort | uniq -c
  • A column product with awk

    printf '3 4\n5 6\n' | awk '{ print $1 * $2 }'
  • Decimals with bc

    echo "scale=4; 22 / 7" | bc