Sort Numeric Array

# Treat $@ as a numeric array and echo it sorted.
function sort_numeric_array {
    sort <(echo $@ | tr ' ' "\n") --numeric-sort | tr "\n" ' '
}

...

for x in {1..10}; do data[$x]=$(($x * $x * -1)
echo $(sort_numeric_array ${data[@]})
-100 -81 -64 -49 -36 -25 -16 -9 -4 -1

Comments

Popular posts from this blog

oche, lik echo but a bit easier to use.

Bithon: Run Python Interactively Inside Bash

Parsing Columns From Files WITHOUT awk