Skip to content

Instantly share code, notes, and snippets.

@abrjagad
Created August 31, 2018 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abrjagad/1132c8a4b59cded6b3372390c042597d to your computer and use it in GitHub Desktop.
Save abrjagad/1132c8a4b59cded6b3372390c042597d to your computer and use it in GitHub Desktop.
Bash: Sort Array by value's length
# 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