Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard in the if statement 1

Status
Not open for further replies.

frangac

Technical User
Feb 8, 2004
163
ZA
Hi All,

How can I use a wildcard in the if statement for e.g

chris=/dog/cat/mouse/biscuit

(Something like this )
if [[ $chris = "%biscuit" ]];then
echo Yes
else
echo No
fi

Many Thanks
Chris
 
#!/bin/ksh

chris=/dog/cat/mouse/biscuit

if [[ $chris = @(*biscuit) ]]; then
echo Yes
else
echo No
fi

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Hi Vlad,

Simple but nice.


Thanks a mil
Chris
 
Also :
[tt]
#!/bin/ksh

chris=/dog/cat/mouse/biscuit

if [[ $chris = *biscuit ]]; then
echo Yes
else
echo No
fi
[/tt]

Jean Pierre.
 
And yet another way, not dependant on ksh:
case $chris in
*biscuit) echo Yes;;
*= echo No;;
esac

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Little typo error PH

case $chris in
*biscuit) echo Yes;;
*) echo No;;
esac

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top