第一种方法:

将source.txt 文件复制4份

#!/bin/bash

i=0

while [ $i -le 4 ]

do

cp -vf source.txt  $i.txt

let i+=1

done

[kdb11new@host4 newtest]$ ll

-rw-r--r-- 1 kdb11new dba 1048627 Jan 28 13:48 1.txt

-rw-r--r-- 1 kdb11new dba 1048627 Jan 28 13:48 2.txt

-rw-r--r-- 1 kdb11new dba 1048627 Jan 28 13:49 3.txt

-rw-r--r-- 1 kdb11new dba 1048627 Jan 28 13:49 4.txt

-rw-r--r-- 1 kdb11new dba 1048627Jan 28 13:21 source.txt

第二种方法:

#!/bin/bash

echo "input your file name"

read  FILENAME

echo "how many times you want copy?"

read TIMES

echo "your file name is ${FILENAME}, you want to copy ${TIMES} times."

BASE=`echo ${FILENAME}|cut -d "." -f 1`

EXT=`echo ${FILENAME}|cut -d "." -f 2`

for(( i=0;i

do

echo "copy ${BASE}.${EXT} to ${BASE}$i.${EXT} ..."

cp "${BASE}.${EXT}" "${BASE}$i.${EXT}"

done

[kdb11new@host4 shell]$ ./makefile

input your file name

secueed.sh

how many times you want copy?

10

your file name is secueed.sh, you want to copy 10 times.

copy secueed.sh to secueed0.sh ...

copy secueed.sh to secueed1.sh ...

copy secueed.sh to secueed2.sh ...

copy secueed.sh to secueed3.sh ...

copy secueed.sh to secueed4.sh ...

copy secueed.sh to secueed5.sh ...

copy secueed.sh to secueed6.sh ...

copy secueed.sh to secueed7.sh ...

copy secueed.sh to secueed8.sh ...

copy secueed.sh to secueed9.sh ...

[kdb11new@host4 shell]$ ll

total 52

-rwxr-xr-x 1 kdb11new dba 424 Jan 28 10:07 makefile

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed0.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed1.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed2.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed3.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed4.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed5.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed6.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed7.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed8.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:08 secueed9.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 10:19 secueed.sh

第三种方法:

#!/bin/bash

echo "input your file name"

read  FILENAME

echo "how many times you want copy?"

read TIMES

echo "your file name is ${FILENAME}, you want to copy ${TIMES} times."

#find . and cut the left part of the file name using ##

EXT=${FILENAME##*.}

#find . and cut the right part of the file name using %

BASE=${FILENAME%.*}

echo "base:$BASE"

echo "ext:$EXT"

for(( i=0;i

do

echo "copy ${BASE}.${EXT} to ${BASE}$i.${EXT} ..."

cp "${BASE}.${EXT}" "${BASE}$i.${EXT}"

done

[kdb11new@host4 shell]$ ./bachfile

input your file name

secueed.sh

how many times you want copy?

11

your file name is secueed.sh, you want to copy 11 times.

base:secueed

ext:sh

copy secueed.sh to secueed0.sh ...

copy secueed.sh to secueed1.sh ...

copy secueed.sh to secueed2.sh ...

copy secueed.sh to secueed3.sh ...

copy secueed.sh to secueed4.sh ...

copy secueed.sh to secueed5.sh ...

copy secueed.sh to secueed6.sh ...

copy secueed.sh to secueed7.sh ...

copy secueed.sh to secueed8.sh ...

copy secueed.sh to secueed9.sh ...

copy secueed.sh to secueed10.sh ...

[kdb11new@host4 shell]$ ll

total 56

-rwxr-xr-x 1 kdb11new dba 491 Jan 28 10:00 bachfile

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed0.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed10.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed1.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed2.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed3.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed4.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed5.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed6.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed7.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed8.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 16:14 secueed9.sh

-rwxr-xr-x 1 kdb11new dba 110 Jan 28 10:19 secueed.sh

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐