<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'd think of two approaches to this. The first is just to throw away any error output. That's probably not ideal, because in case something goes wrong (destination volume full, etc) you won't know.</div><div><br></div><div>The other is to generate an array of files, then wrap your loop in an if statement. "if" might not seem super cool, but it might do the trick for you:</div><div><br></div><div>$ cat backup.sh</div><div>prefix=<set the date or whatever></div><div>files=([a-z]*)</div><div><div><div>if [ -e "${files[0]}" ]; then</div><div> for f in "${files[@]}"; do</div><div> mv "$f" "$prefix-$f"</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 "elegant" 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't tested this, so consider it metacode -</div><div><br></div><div>find . -name '^[a-z]*' -maxdepth 1 -exec mv "{}" "$prefix-{}" \;</div><div><br></div><div>* I tested this find command and it is wrong (needs revising), but it's the idea that counts, right? ;)</div><div><br></div></body></html>