Discussion: changing extention
Afficher un message
Vieux 25/03/2008, 00h06   #4
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: changing extention

On 2008-03-24, sid wrote:
> I want to know if it it possible to change a filename extention to
> another one using a shell script. eg. Reading a foo.c file and
> renaming it to foo.cpp using a script and this is read using a for
> loop, so say $i=foo.c, now the $i has to be changed to get foo.cpp.
> I've been able to do it using 'basename' is there some other way to do
> it?


Since all you need to do is add 'pp':

mv "$i" "${i}pp"

If you want to change any extension to '.cpp':

mv "$i" "${i%.*}.cpp"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
 
Page generated in 0,04665 seconds with 9 queries