title: Appending a character to every element except the last one of a bash array
body: <p>I am looking to append each element of a bash array with <code>|</code> except the last one.</p>
  
  <pre><code>array=("element1" "element2" "element3")
  </code></pre>
  
  <p>My desired output would be </p>
  
  <pre><code>array=("element1"|"element2"|"element3")
  </code></pre>
  
  <p>What I have done</p>
  
  <pre><code>for i in ${!array[@]}; 
  do
  array1+=( "${array[$i]}|" )
  done
  </code></pre>
  
  <p>Followed by </p>
  
  <pre><code>array=echo ${array1[@]}|sed 's/|$//'
  </code></pre>
  
  <p>Is there any other looping approach I can use that only appends the character until the last but one element?</p>