4 ms·
Extremely common pattern in the shell world. I'd be very surprised if this hasn't been published before 2021. for i in {1..10} ; for j in {1..10} ; [ $a[$i] -l
by casey2 2y ago
Extremely common pattern in the shell world. I'd be very surprised if this hasn't been published before 2021.
for i in {1..10} ; for j in {1..10} ; [ $a[$i] -lt $a[$j] ] && t=$a[$i] && a[$i]=$a[$j] && a[$j]=$t ; echo $a
As for intuition the only thing I can come up with is that better than "it's a double for loop with a cmp and a swap, of course it will sort" is that after every i_th loop the 1..i_th elements are sorted.