compare “n” number of variables

An easy way to compare “n” number of variables in bash, precisely to find if all of them are equal or not, can be easily done in the following way:

while [ $i -lt 10 ]; do
Sequence[$i]=whatever sequence you want
let i=$i+1
done

for i in ${Sequence[*]}; do
[ "${Sequence[0]}" = "$i" ]
j=$(( $? + j ))
done

if [ $j -eq 0 ];
echo="they are all the same"
fi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.