Bourne Shell - if someone enters a variable that begins with...

sorry, i know my questions are kind of basic, but i'm hoping you guys can help out

lets say if the user enters something that begins with "BL" but can be anything like BLsdf or BLUE or something..how can i figure this out?  I know it should be something along the lines of "BL"* or something but i'm not sure... if someone can point me in the right direction

i'm really trying to learn here

#!/bin/sh
echo -n "Enter a color: "
read color
if [ $color = bl* ]
then
 echo "blue"
fi

Open in new window

nocturn4lAsked:
Who is Participating?
 
ozoCommented:
case $color in
 bl* ) echo "blue" ;;
esac
0
 
nocturn4lAuthor Commented:
thanks again ozo, you're awesome.  is this something you can only do using case instead of 'if'?  still learning here, thanks again.
0
 
ozoCommented:
if expr "$color" : 'bl*' ; then echo blue ; fi
0
 
nocturn4lAuthor Commented:
thank you!  learning alot from everyone here
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.