0
host_list=abc@xyz.com,cde@xyz.com,zbe@xyz.com

I want to write loop in bash script to scroll through each of this host_list & try to grep a particular string 'abc@xyz.com'. if its present then return yes or no

dbNovice
  • 399
  • 2
  • 4
  • 18
  • Is there a reason you're using a string variable instead of an array? – Charles Duffy May 10 '21 at 19:35
  • `host_list=( abc@xyz.com cde@xyz.com zbe@xyz.com )` would be more sensible; then you can just `for host in "${host_list[@]}"; do ...` – Charles Duffy May 10 '21 at 19:36
  • In evaluating answers in the linked duplicates, keep [BashPitfalls #50](https://mywiki.wooledge.org/BashPitfalls#hosts.3D.28_.24.28aws_....29_.29) in mind. `array=( $string )` is an antipattern -- while commonly used, it introduces bugs. – Charles Duffy May 10 '21 at 19:38

0 Answers0