I have 2 strings:answer=spaghettiguess=spghetiI would like to know if there was some way to count the amount of letters in $answer that are same as $guess, in this case I should get number 7. Some notes are that $answer and $guess will change.'Because of the accusation that I posted a duplicate, the one suggested is asking for length of word; I am asking for how many letters in 2 strings are equal. For example, Stackoverflow and stkflw. would want something to count how many letters in stkflw are equal to the letters in Stackoverflow.I need it to count all letters in a word, for an example, Test should return 4 because it has 4 letters (an answer has one that returns 3 with test which is not desirable) If this could be done in bash, that would be great! :)
See how many words have same letters
bash;text processing
answer=spaghettiguess=aeghipstt# find the individual letters in the answer# use an associative array to manage duplicatesdeclare -A letters=()for ((i=0; i < ${#answer}; i++)); do    letters[${answer:i:1}]=1done# remove duplicate letters in the guess.# could use the above technique, but here's another oneguess_uniq=$( sed 's/./&\n/g' <<< $guess | sort -u | tr -d '\n' )# loop over the unique letters of the guess, # and count how many letters are in the answermatches=0for ((i=0; i < ${#guess_uniq}; i++)); do    [[ ${letters[${guess_uniq:i:1}]} = 1 ]] && (( matches++ ))doneif (( matches == ${#guess_uniq} )); then echo Correct; fi