<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap:break-word"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div> <br> <div id="bloop_sign_1485800305798890240" class="bloop_sign"></div> <br><p class="airmail_on">On January 30, 2017 at 11:57:53, <a href="mailto:jep200404@columbus.rr.com">jep200404@columbus.rr.com</a> (<a href="mailto:jep200404@columbus.rr.com">jep200404@columbus.rr.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>How does one do nothing gracefully in a Bourne shell for loop?<br><br>A example that fails to do nothing gracefully follows.<br></div></div></span></blockquote><div><br></div><div>Typically, I&#39;d think of two approaches to this. The first is just to throw away any error output. That&#39;s probably not ideal, because in case something goes wrong (destination volume full, etc) you won&#39;t know.</div><div><br></div><div>The other is to generate an array of files, then wrap your loop in an if statement. &quot;if&quot; might not seem super cool, but it might do the trick for you:</div><div><br></div><div>$ cat backup.sh</div><div>prefix=&lt;set the date or whatever&gt;</div><div>files=([a-z]*)</div><div><div><div>if [ -e &quot;${files[0]}&quot; ]; then</div><div>    for f in &quot;${files[@]}&quot;; do</div><div>        mv &quot;$f&quot; &quot;$prefix-$f&quot;</div><div>    done</div><div>fi</div></div></div><div><br></div><div>The advantage this if/loop has over a more compact or perhaps &quot;elegant&quot; approach is that it tries to be readable.</div><div><br></div><div>An option that might be slightly less readable but could be done in fewer lines (eliminates the explicit loop construct entirely) is to use `find` with exec mv or xargs. I haven&#39;t tested this, so consider it metacode -</div><div><br></div><div>find . -name &#39;^[a-z]*&#39; -maxdepth 1 -exec mv &quot;{}&quot; &quot;$prefix-{}&quot; \;</div><div><br></div><div>* I tested this find command and it is wrong (needs revising), but it&#39;s the idea that counts, right? ;)</div><div><br></div></body></html>