<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>On Thu, Sep 26, 2019, at 08:02, Cedric Puddy wrote:<br></div><blockquote type="cite" id="qt"><div>I've always done as Jason suggests, but the one thing that is usually helpful is the addition of "basename":<br></div><div><br></div><div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">for $FILE in *</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">do</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">mv $FILE $(basename $FILE .htm).whatever</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">done</span></span><br></div></div></div></blockquote><div><br></div><div>Basename will remove an arbitrary string (eg: .htm) from the end of another string, thus getting rid of the old extension, so you can tack on your new ".html" or ".whatever" extension.<br></div></div></blockquote><div><br></div><div>For a one-off, this is generally what I do too.<br></div><div><br></div><div>However, if you're scripting a loop, it may save a fair amount of time by switching to bash builtins instead of calling basename in every loop. I recently cut down a script that took ~12 seconds to run to about 1 second by eliminating sed and basename calls from within a loop. (the output fed a user screen, so it was noticeable). Also, it stopped churning through a few thousand PIDs while running.<br></div><div><br></div><div>(Also, don't forget quotes, or you'll have a bad time)<br></div><div><br></div><div><div> <span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight">for FILE in *</span></span><br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight"> do</span></span><br></div><div> # Echo just for safety incase somebody copy/pastes this.<br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight"> echo mv "$FILE" "${FILE%.*}.whatever</span></span>"<br></div><div><span style="color:#000000" class="colour"><span style="background-color:rgba(255, 255, 255, 0)" class="highlight"> done</span></span><br></div><div><br></div></div><div id="sig91988184"><div class="signature">-- <br></div><div class="signature"><b>Chris Irwin</b><br></div><div class="signature"><br></div><div class="signature"><span style="font-family:menlo, consolas, monospace, sans-serif" class="font">email: </span><a href="mailto:chris@chrisirwin.ca"><span style="font-family:menlo, consolas, monospace, sans-serif" class="font">chris@chrisirwin.ca</span></a><span style="font-family:menlo, consolas, monospace, sans-serif" class="font"></span><br></div><div class="signature"><span style="font-family:menlo, consolas, monospace, sans-serif" class="font"> xmpp: </span><a href="mailto:chris@chrisirwin.ca"><span style="font-family:menlo, consolas, monospace, sans-serif" class="font">chris@chrisirwin.ca</span></a><span style="font-family:menlo, consolas, monospace, sans-serif" class="font"></span><br></div><div class="signature"><span style="font-family:menlo, consolas, monospace, sans-serif" class="font"> web: </span><a href="https://chrisirwin.ca"><span style="font-family:menlo, consolas, monospace, sans-serif" class="font">https://chrisirwin.ca</span></a><br></div></div><div><br></div></body></html>