LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   copy file and rename n times in succession (http://www.linuxquestions.org/questions/linux-newbie-8/copy-file-and-rename-n-times-in-succession-4175440528/)

coryjsanders 12-07-2012 10:56 PM

copy file and rename n times in succession
 
I have this:
#!/bin/bash
#copies named iax modem and saves in ensuing order

cp /etc/iaxmodem/iaxmodem-cfg.ttyIAX20 /etc/iaxmodem/iaxmodem-cfg.ttyIAX21

But would like to create the contents of iaxmodem-cfg.ttyIAX20 n more times and name 22, 23 24, etc

colucix 12-07-2012 11:31 PM

Use a loop:
Code:

for c in {22..28}
do
  cp /etc/iaxmodem/iaxmodem-cfg.ttyIAX20 /etc/iaxmodem/iaxmodem-cfg.ttyIAX$c
done


shivaa 12-08-2012 12:06 AM

Or alternatively you can use:
Code:

#!/bin/bash
echo -n "Enter how many times: "; read times
n=20
while [ $n -le $times ]
do
cp  /etc/iaxmodem/iaxmodem-cfg.ttyIAX /etc/iaxmodem/iaxmodem-cfg.ttyIAX$n
n=$((n+1))
done



All times are GMT -5. The time now is 06:12 PM.