Last active
August 29, 2015 14:17
-
-
Save ahmadtawakol/ce23138ef7449f0c4869 to your computer and use it in GitHub Desktop.
Tests if two strings are an anagram. Run it with `./anagramTest.sh string1 string2`
This file contains 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
#!/bin/bash | |
string1=$1 | |
string2=$2 | |
count=0 | |
if [[ -e "$string2" || ( ${#string1} -ne ${#string2} ) ]] | |
then | |
echo "Not an anagram." | |
else | |
for (( i=0; i<${#string1}; i++ )) | |
do | |
if [[ "$string2" =~ ${string1:$i:1} ]] | |
then | |
((count++)) | |
fi | |
done | |
if [ $count -eq ${#string1} ] | |
then | |
echo "Anagram!" | |
else | |
echo "Not an anagram." | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand anything :D