bashif-statementechoglobpangram

String contains character bash


In bash, I'm trying to test whether a sentence is a pangram.

read sentence
if [[ "$sentence" == [Aa] && [Bb] && [Cc] && [Dd] && [Ee] && [Ff] && [Gg] && [Hh] && [Ii] && [Jj] && [Kk] && [Ll] && [Mm] && [Nn] && [Oo] && [Pp] && [Qq] && [Rr] && [Ss] && [Tt] && [Uu] && [Vv] && [Ww] && [Xx] && [Yy] && [Zz] ]]; then
echo "pangram"
else
echo "not pangram"
fi

This is the code I have so far, and all I'm getting is an output of "not pangram". Does anyone know what is wrong with my code?

I was trying to manipulate the code from a previous question of mine.


Solution

  • Your syntax is almost right, but needs a bit more repetition. You'll need something like:

    [[ "$sentence" =~ [Aa] && "$sentence" =~ [Bb] && "$sentence" =~ [Cc] && ... ]]
    

    There are undoubtedly more succinct ways to do this.