Skip to content

Instantly share code, notes, and snippets.

@MiteshShah
Created July 4, 2016 09:04
Show Gist options
  • Save MiteshShah/ffaea2bcde07c29bf25ee4a283a6a604 to your computer and use it in GitHub Desktop.
Save MiteshShah/ffaea2bcde07c29bf25ee4a283a6a604 to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "Enter Array: "
read -a array
echo "Total Element = ${#array[@]}"
IFS=$'\n' sorted=($(sort -n <<<"${array[*]}"))
echo
echo Sorted Array = ${sorted[@]}
for i in $(sort -un <<<"${array[*]}")
do
count=0;
for j in ${sorted[@]}
do
# echo i = $i
# echo j = $j
if [[ $i -eq $j ]]; then
count=$((count+1))
# echo count = $count
fi
done
echo $count $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment