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
  • 328
  • 1
  • 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
  • 713,503
  • 59
  • 514
  • 593
0

you can also

s='name@gmail.com'

[[ "$s" =~ (.*)@(.*)\.com ]] && echo "name: ${BASH_REMATCH[1]} domain ${BASH_REMATCH[2]}.com"
jm666
  • 58,683
  • 17
  • 101
  • 180