Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] banal bash script opinion



Hi.

I wanted to write a script that I pass the name of a file, the new name I want 
it had and a number indicating the number of copies of that file with the new 
names that I want.

Do it for me thanks ..

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

ps: don't get furious it was a joke ;-)

I wrote the script and it worked well for my needs. I just wanted to know some 
suggestions about it, if it could be made in less lines.
I know this is a banal script but I'm learning bash scripting.

Thank you in advance.

I pass the name of an existing file, the new name for the copies and the numer

./scriptname filename.extension newfilename.extension number_of_copies

#!/bin/bash

x=0
extension=$(echo $1 | sed -n -e 's/[[:print:]]*\.//gp')
if [ -z $extension ]
then

     while [ $x -lt $3 ]
     do
         cp $1 $2$x
         x=`expr $x + 1`
     done

else

     while [ $x -lt $3 ]
     do
         cp $1 $2$x.$extension
         x=`expr $x + 1`
     done
fi


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links