title: pitfalls in renaming files in bash
body: <p>I am reading a guide here
  <a href="http://mywiki.wooledge.org/BashFAQ/030" rel="nofollow">http://mywiki.wooledge.org/BashFAQ/030</a>
  on this link a few examples are given I am trying to understand them one example code says</p>
  
  <pre><code># Bash
  # Replace all spaces with underscores
  for f in *\ *; do mv -- "$f" "${f// /_}"; done
  </code></pre>
  
  <p>what I have known till now was use of a backslash for special characters like space of ~ or # etc in case of search and replace 
  examples or in shell scripts here in above example they have<br>
  used  <code>${f// /_}</code><br>
  forward slashes , I am not clear with this is this allowed?<br>
  in another example on same page
  they give an example to remove space and replace it with underscores </p>
  
  <p><code>find . -depth -name "* *" -exec bash -c 'dir=${1%/*} base=${1##*/};<br>
   mv "$1" "$dir/${base// /_}"' _ {} \;</code></p>
  
  <p>in above example I am not clear with following<br>
  1) <code>dir=${1%/*}</code><br>
  2) <code>base=${1##*/}</code><br>
  3) and when it says <code>mv "$1"</code> what is meant by $1 in the above statement,<br>
  4) finally the find command is being closed with <code>-exec &lt;something&gt; _ {} \;</code><br>
  now what is the use of an underscore _ ,curly braces  {} and a backslash followed by a colon above \;?<br>
  in the third example they say  </p>
  
  <pre><code># tolower - convert file names to lower case
  # POSIX
  for file in "$@"do 
     [ -f "$file" ] || continue                # ignore non-existing names   
   newname=$(echo "$file" | tr '[:upper:]' '[:lower:]')     # lower case   
   [ "$file" = "$newname" ] &amp;&amp; continue      # nothing to do   
   [ -f "$newname" ] &amp;&amp; continue             # don't overwrite existing files  
    mv -- "$file" "$newname"done 
  </code></pre>
  
  <p>I am not clear with following lines<br>
  5) <code>[ -f "$file" ] || continue # ignore non-existing names</code><br>
  I am not clear with [ ] tests the condition if $file exists then what is the use of OR condition || here and the continue statement<br>
  6) <code>[ -f "$newname" ] &amp;&amp; continue # don't overwrite existing files</code> same doubt here as in point 5</p>