Skip to content

Instantly share code, notes, and snippets.

@ahmadtawakol
Last active August 29, 2015 14:17
Show Gist options
  • Save ahmadtawakol/ce23138ef7449f0c4869 to your computer and use it in GitHub Desktop.
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`
#!/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
@aessam
Copy link

aessam commented Mar 26, 2015

I don't understand anything :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment