用shell指令碼複製N份檔案方法
阿新 • • 發佈:2019-02-13
#!/bin/sh
echo "Please input your file name"
read FILENAME
echo "How many times you want copy?"
read TIMES
echo "Your file name is ${FILENAME}, The times you want to copy is ${TIMES} ."
EXT=${FILENAME##*.}//這個是檔案的名稱,例如face.jpg這裡的EXT就是face
#find . and cut the right part of the file name using %
BASE=${FILENAME%.*}//這個是檔案的字尾名稱,例如face.jpgBAST即為jpg
echo "base:$BASE"
echo "ext:$EXT"
do
echo "copy ${BASE}.${EXT} to ${BASE}$i.${EXT} ..."
cp "${BASE}.${EXT}" "${BASE}$i.${EXT}"//迴圈cope
done
echo "Please input your file name"
read FILENAME
echo "How many times you want copy?"
read TIMES
echo "Your file name is ${FILENAME}, The times you want to copy is ${TIMES} ."
EXT=${FILENAME##*.}//這個是檔案的名稱,例如face.jpg這裡的EXT就是face
#find . and cut the right part of the file name using %
BASE=${FILENAME%.*}//這個是檔案的字尾名稱,例如face.jpgBAST即為jpg
echo "base:$BASE"
echo "ext:$EXT"
for(( i=0;i<${TIMES};i++))//這裡要使用類似C語言的for語句就要進行一下操作:1)chmod 777 指令碼名稱.sh 2)./指令碼名稱.sh
echo "copy ${BASE}.${EXT} to ${BASE}$i.${EXT} ..."
cp "${BASE}.${EXT}" "${BASE}$i.${EXT}"//迴圈cope
done