Register
It is currently Mon Sep 01, 2014 7:41 am

need a script to rename the extension of a file


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Thu Apr 16, 2009 10:01 am   

Joined: Thu Apr 16, 2009 9:54 am
Posts: 5
Hey,

I need a script that rename a file extension in .hello
for example
./renamer.sh test.txt
and I should test if the file exist
if it exist it should rename it to test.hello
if not it should write error

Can someone help me with this.

Thank you


Top
 Profile  
 PostPosted: Thu Apr 16, 2009 4:21 pm   

Joined: Thu Apr 16, 2009 9:54 am
Posts: 5
I found it myself after a little bit of testing.
It`s my first script that I write.

So I`m very pleased to have found it myself

#!/bin/bash
if [ -f $1 ];
then
echo ok
mv ./"$1" "${1%.*}.hello";
else
echo "error"
fi


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP