The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 12-19-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,892
With all Bourne-type shells* you can use case and wildcards pattern matching (*I believe the csh family uses a different syntax):

Code:
a="string with piece to search"

case $a in
  *piece*) printf "OK\n";;
        *) printf "KO\n";;
esac
With ksh93, zsh and bash:

Code:
[[ $a == *piece* ]]&&printf "OK\n"||printf "KO\n"
With some versions of the above shells you can even match using regular expressions with the =~ operator.

Last edited by radoulov; 12-19-2008 at 04:40 PM..