Monatsarchiv für Februar 2011

 
 

Bash: Sleepsort Algorithm

Some code that a friend showed to me was this:

#!/bin/bash

function f() {
  sleep "$1"
  echo "$1"
}

while [ -n "$1" ]
do
  f "$1" &
  shift
done

wait

Example:

./sleepsort 9 3 7 1 3 2 4 7 4 6

He called it "sleepsort". And somehow, it really works. Not the fastest, but it works.