title: How do I split a string on a delimiter in Bash?
body: <p>I have this string stored in a variable:</p>
  
  <pre><code>IN="bla@some.com;john@home.com"
  </code></pre>
  
  <p>Now I would like to split the strings by <code>;</code> delimiter so that I have:</p>
  
  <pre><code>ADDR1="bla@some.com"
  ADDR2="john@home.com"
  </code></pre>
  
  <p>I don't necessarily need the <code>ADDR1</code> and <code>ADDR2</code> variables. If they are elements of an array that's even better.</p>
  
  <hr>
  
  <p>After suggestions from the answers below, I ended up with the following which is what I was after:</p>
  
  <pre><code>#!/usr/bin/env bash
  
  IN="bla@some.com;john@home.com"
  
  mails=$(echo $IN | tr ";" "\n")
  
  for addr in $mails
  do
      echo "&gt; [$addr]"
  done
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>&gt; [bla@some.com]
  &gt; [john@home.com]
  </code></pre>
  
  <p>There was a solution involving setting <a href="http://en.wikipedia.org/wiki/Internal_field_separator" rel="noreferrer">Internal_field_separator</a> (IFS) to <code>;</code>. I am not sure what happened with that answer, how do you reset <code>IFS</code> back to default?</p>
  
  <p>RE: <code>IFS</code> solution, I tried this and it works, I keep the old <code>IFS</code> and then restore it:</p>
  
  <pre><code>IN="bla@some.com;john@home.com"
  
  OIFS=$IFS
  IFS=';'
  mails2=$IN
  for x in $mails2
  do
      echo "&gt; [$x]"
  done
  
  IFS=$OIFS
  </code></pre>
  
  <p>BTW, when I tried </p>
  
  <pre><code>mails2=($IN)
  </code></pre>
  
  <p>I only got the first string when printing it in loop, without brackets around <code>$IN</code> it works.</p>