<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif;font-size:small">If it works in ksh, that suits me. Never made the leap to bash as such.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 6, 2016 at 9:13 PM, Alex Carver <span dir="ltr"><<a href="mailto:agcarver+ale@acarver.net" target="_blank">agcarver+ale@acarver.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I can't remember. I know it works in bash and ksh. I don't think I<br>
ever tried it in sh.<br>
<span class="im HOEnZb"><br>
On 2016-04-06 17:48, Pete Hardie wrote:<br>
> One question on that - I assume it's bash only and not original(tm) Bourne shell?<br>
><br>
> On Wed, Apr 6, 2016 at 8:08 PM, Alex Carver <<a href="mailto:agcarver%2Bale@acarver.net">agcarver+ale@acarver.net</a><br>
</span><span class="im HOEnZb">> <mailto:<a href="mailto:agcarver%2Bale@acarver.net">agcarver+ale@acarver.net</a>>> wrote:<br>
><br>
> No echos, other commands or subshells here, use bash built-in regex:<br>
><br>
> (Make a subdirectory to accept the destination files to make things<br>
> cleaner or put the sources in a subdir and move the destinations up a level)<br>
><br>
> #!/bin/bash<br>
> subdir=subdirname<br>
> for f in * (or *.* or whatever pattern you want)<br>
> do<br>
> cp $f ${subdir}/${f%.*}.txt<br>
> done<br>
><br>
><br>
><br>
><br>
> %.* trims everything from f after the last dot (including the dot)<br>
> returning the prefix<br>
> %%.* is greedier and will trim everything after the first dot<br>
><br>
><br>
> On 2016-04-06 15:39, Pete Hardie wrote:<br>
> > perhaps something lile this:<br>
> ><br>
> > for file in *.*<br>
> > do<br>
> > parts = $(echo $file| tr "." " ")<br>
> > bname = `basename $parts[0] $parts[1]`<br>
> > cp $file ${bname}.txt #or whatever processing you are doing here with $file<br>
> > the whole name and $base the name sans suffix<br>
> > done<br>
> ><br>
> ><br>
> ><br>
> > On Wed, Apr 6, 2016 at 6:27 PM, Pete Hardie <<a href="mailto:pete.hardie@gmail.com">pete.hardie@gmail.com</a> <mailto:<a href="mailto:pete.hardie@gmail.com">pete.hardie@gmail.com</a>><br>
</span><span class="im HOEnZb">> > <mailto:<a href="mailto:pete.hardie@gmail.com">pete.hardie@gmail.com</a> <mailto:<a href="mailto:pete.hardie@gmail.com">pete.hardie@gmail.com</a>>>> wrote:<br>
> ><br>
> > Is the issue that you don't want a separate command for each suffix, or that<br>
> > you will not know all the suffixes ahead of time?<br>
> ><br>
> > On Wed, Apr 6, 2016 at 6:22 PM, Scott M. Jones <<a href="mailto:eff@dragoncon.org">eff@dragoncon.org</a> <mailto:<a href="mailto:eff@dragoncon.org">eff@dragoncon.org</a>><br>
</span><div class="HOEnZb"><div class="h5">> > <mailto:<a href="mailto:eff@dragoncon.org">eff@dragoncon.org</a> <mailto:<a href="mailto:eff@dragoncon.org">eff@dragoncon.org</a>>>> wrote:<br>
> ><br>
> > Great answers in Stack Overflow, including a bash-only solution.<br>
> ><br>
> ><br>
> <a href="http://stackoverflow.com/questions/15060384/one-liner-in-bash-using-perl-or-awk-to-change-extension-of-multiple-files" rel="noreferrer" target="_blank">http://stackoverflow.com/questions/15060384/one-liner-in-bash-using-perl-or-awk-to-change-extension-of-multiple-files</a><br>
> ><br>
> > On 4/6/16 5:52 PM, leam hall wrote:<br>
> > > I'm trying to do something simple, change the ending of a script to<br>
> > > ".txt". So if it's my_script.sh it becomes my_script.txt.<br>
> Likewise for<br>
> > > my_script.rb, etc. The .txt version will have the documentation and<br>
> > > comments.<br>
> > ><br>
> > > So far all I've some up with is:<br>
> > ><br>
> > > IS_SH=`echo ${SCRIPTNAME} | grep -c sh$`<br>
> > ><br>
> > > For each expected script ending. Which seems a really ugly<br>
> thing to do.<br>
> > > Is there a better way in Bourne shell to do this?<br>
> > ><br>
> > > Leam<br>
> ><br>
><br>
<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" rel="noreferrer" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">Pete Hardie<br>--------<br>Better Living Through Bitmaps</div>
</div>