Bash typing test
Bash scripts glue the command line together, and they're full of characters you rarely type in prose: $ before variables, (( )) for arithmetic and {1..15} to expand a range. Blocks close with unusual words: fi ends an if (it's if backwards) and done ends a loop.
What you'll type in Bash
$before variables, as in"$i"and$1.(( ))for arithmetic, and$(( ))to use the result.{1..15}brace expansion for ranges.; thenand; doat the end ofifandforlines.fianddoneto close blocks.&&to run a command only if the one before it succeeded.
Example: FizzBuzz in Bash
Each condition sits inside double parentheses with a space at each end: (( i % 15 == 0 )). Bash would accept it without those spaces, but here you type the program exactly as shown.
for i in {1..15}; do
if (( i % 15 == 0 )); then
echo "FizzBuzz"
elif (( i % 3 == 0 )); then
echo "Fizz"
elif (( i % 5 == 0 )); then
echo "Buzz"
else
echo "$i"
fi
done
Tips for typing Bash faster
; thenand; dodo the job a brace does in other languages. Type the semicolon and the keyword as one phrase.- A quoted variable like
"$i"has three shifted characters out of four. Keep Shift moving smoothly between them. - Bash has no objects, so the binary search tree program keeps its tree in arrays. It's long, and a real test of accuracy.
All 20 Bash programs
Every program is real, working Bash. Choose one to start typing it straight away.
Beginner
- Hello, World!Print a greeting.
- Count to fivePrint the numbers 1 to 5.
- Celsius to FahrenheitConvert 100 °C to Fahrenheit.
- Sum a listAdd up 3, 1, 4, 1, 5.
- Find the largestFind the biggest number in a list.
- Count vowelsCount the vowels in "keyboard".
Intermediate
- Reverse a stringTurn "hello" into "olleh".
- FizzBuzzFizz for 3s, Buzz for 5s, 1 to 15.
- FactorialA recursive function, called with 5.
- FibonacciPrint the first ten Fibonacci numbers.
- Greatest common divisorEuclid's algorithm for 48 and 18.
Advanced
- Primes to 20Print every prime up to 20.
- PalindromeCheck whether "racecar" reads the same backwards.
- Word countCount the words in a sentence.
- Bubble sortSort 5, 2, 9, 1, 7 by swapping neighbours.
- Binary searchFind 7 in a sorted list by halving.
Expert
- QuicksortSort a list by partitioning around a pivot.
- Binary search treeBuild a tree, then read the values back in order.
- Shortest path (BFS)Breadth-first search through a small graph.
- N-QueensCount the ways to place 6 queens so none attack.
How the test works
The timer starts on your first key and stops once every character is right. Press Enter for a new line and the indentation is filled in for you. A wrong key shows in red and counts as a mistake; press Backspace to go back and fix it. Your best time for each program is saved in your browser. Read more about how speed and accuracy are calculated, or get tips for typing code faster.