On Thu, May 14, 2009 at 9:26 AM, Charles Howse <span dir="ltr"><<a href="mailto:chowse@charter.net">chowse@charter.net</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
I need to batch rename all files with extension .PDF to extension .pdf.<br>
They may or may not have spaces in the filenames.<br>
<br>
The following works ONLY if there are no spaces in the filename:<br>
<br>
for f in *.PDF; do<br>
base=`basename $f .PDF`<br>
mv $f $base.pdf<br>
done<br>
<br>
Can anyone provide a tip to something that will work regardless of whether there are spaces in the filenames or not?</blockquote><div><br>Enclosing a variable in double quotes prevents parameter expansion. See the quoting section of the shell you're using. (Which you failed to mention.)<br>
<br>Using back quotes, ``, for command substitution is deprecated for various reasons. Use $(), it will make your life simpler.<br><br>${base} forces correct parameter expansion, e.g. it states clearly to others that 'base' is the variable not 'base.pdf'.<br>
<br>for f in *.PDF; do<br> base=$(basename "$f" .PDF)<br> mv "$f" "${base}".pdf<br>done<br><br>Phil<br> </div></div>