Created
August 31, 2018 13:31
-
-
Save abrjagad/1132c8a4b59cded6b3372390c042597d to your computer and use it in GitHub Desktop.
Bash: Sort Array by value's length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Performing Bubble sort | |
for ((i = 0; i<${#array[@]}-1; i++)) | |
do | |
# echo $i | |
for((j = 0; j<${#array[@]}-1; j++)) | |
do | |
if ((${#array[j]} < ${#array[$((j+1))]})) | |
then | |
temp=${array[$j]} | |
array[$j]=${array[$((j+1))]} | |
array[$((j+1))]=$temp | |
fi | |
done | |
done | |
printf "%s\n" "${array[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment