Skip to content

Instantly share code, notes, and snippets.

@eiiches
Created April 18, 2011 02:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eiiches/924692 to your computer and use it in GitHub Desktop.
Save eiiches/924692 to your computer and use it in GitHub Desktop.
Quicksort in Bash
#!/bin/bash
filter () {
f="$1"; shift
for e in "$@"; do
if $f "$e"; then
echo -n "$e "
fi
done
}
qsort () {
if [ $# -gt 1 ]; then
p="$1"; shift
qsort $(filter "test $p -lt" "$@")
echo -n "$p "
qsort $(filter "test $p -ge" "$@")
elif [ $# -eq 1 ]; then
echo -n "$1 "
fi
}
qsort 10 3 5 2 20
@danshaman05
Copy link

it doesnt work for more than 6 numbers

@gabolaev
Copy link

it's the best gist i ever seen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment