title: sed - batch 'key=value' substitute
body: <p>I'm working on a function to perform multiple <code>key=value</code> substitutions with <code>sed</code>:</p>
  
  <pre><code>batch_sub () {
      local file="${@: -1}" # Last argument is file to be changed.
      [[ -w "${file}" ]] || { echo "Invalid file: ${file}" ; return 1 ; }
      for arg in "${@}" ; do
          [[ $arg =~ (.*)=(.*) ]] || continue
          # 'trim_str' will trim leading &amp; trailing spaces.
          local key=$(trim_str "${BASH_REMATCH[1]}")
          local value=${BASH_REMATCH[2]}
          sed -i 's@'"\(${key}"' *=\).*@\1'"${value}"'@' "${file}"
      done
  }
  </code></pre>
  
  <p>this function accepts arguments like:</p>
  
  <pre><code>batch_sub "a = x" "b = y" "c = z" "a.b.d.e=udp://b:8080" "/tmp/file"
  </code></pre>
  
  <p>and works fine.  But what I want is to make it accept arguments like this:</p>
  
  <pre><code>batch_sub "a = x b = y c = z a.b.d.e=udp://b:8080" "/tmp/file"
  </code></pre>
  
  <p>Furthermore, it would be nice if <code>sed</code> is invoked only once inside this function:</p>
  
  <pre><code>sed -i -e 's/$key=/\1$value/'
         -e 's/$key1=/\1$value1/'
         '/tmp/file'
  </code></pre>
  
  <p>please advise.</p>