title: Bash Script; Replacing certain string in filename with another string using find and sed
body: <p>I'm trying to create a bash script that replaces certain string in filename with another string using find command and sed command. </p>
  
  <p>I want to take two arguments; first being variable OLD, the string I'm looking for in filename (string may also contain spaces), second being variable NEW, the string I want to change it to.  </p>
  
  <p>I want to find all files that contains OLD in filename AND ends with .jpg or .png in current directories and all subdirectories and change the OLD part with NEW.</p>
  
  <pre><code>#! /bin/bash
  
  OLD="${1}"
  NEW="${2}"
  
  # maybe..?
  for file in `find . -name "*$OLD*\.(jpg|png)"`; do
     # ...
  done
  
  # or this..?
  find . -name "*$OLD*\.(jpg|png)" | sed -E "s/$OLD/$NEW/"
  # ...
  </code></pre>
  
  <p>I have wrote some things but they probably don't make any sense and I'm really confused with bash scripting as I am still very new to it. I will really appreciate any help. Thank you!</p>