0

String :

 name@gmail.com

Want to check for :

@
.com

if those two are found, I want to set my boolean true

bool_one=true

How do I do this? I tried

if [ $word|grep[@] = $word]

but it's not working.

Dan
  • 358
  • 2
  • 3
  • 17
  • 1
    possible duplicate of [String contains in bash](http://stackoverflow.com/questions/229551/string-contains-in-bash) – pfnuesel Mar 18 '14 at 18:46

2 Answers2

2

You can do it like this:

s='name@gmail.com'

[[ "$s" == *@*.com ]] && echo "true"
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

you can also

s='name@gmail.com'

[[ "$s" =~ (.*)@(.*)\.com ]] && echo "name: ${BASH_REMATCH[1]} domain ${BASH_REMATCH[2]}.com"
clt60
  • 62,119
  • 17
  • 107
  • 194