linux - check if the input is a vowel -
i origin bash scripting , implementing of have studied in other programming languages bash. have check if user has entered vowel character. came this:
#!/bin/bash read -p "enter something: " char if [[ $char -eq [aeiouaeiou]* ]]; echo "vowel" else echo "consonant" fi
but when run on ideone, error:
prog.sh: line 3: [[: [aeiouaeiou]*: syntax error: operand expected (error token "[aeiouaeiou]*")
can please tell me wrong here , how go correcting it?
i know other not-so-clean way have multiple conditions ||
ed together. trying avoid that.
you need utilize ==
operator glob matching:
#!/bin/bash read -p "enter something: " char if [[ "$char" == *[aeiouaeiou]* ]]; echo "vowel" else echo "consonant" fi
-eq
- used matching numbers
as per man test
:
integer1 -eq integer2 integer1 equal integer2
linux bash scripting
No comments:
Post a Comment