변수를 사용하여 파일 이름을 바꾸려고 합니다.
예 2014.001.**.**.**.D890.E.m
: IP.PMST..BHE.D.2014.001
.
내 스크립트는 다음과 같습니다
#!/bin/bash
cd /home/pintolcv/Downloads
for jd in {001..366}
do
mv 2014.$jd.*.*.D890.E.m IP.PMST..BHE.D.2014.$jd
done
하지만 항상 다음 오류가 표시됩니다.
mv: cannot stat `2014.001.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.002.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.003.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.004.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.005.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.006.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.007.*.*.D890.E.m': No such file or directory
mv: cannot stat `2014.008.*.*.D890.E.m': No such file or directory
..
..
.. and so on!
어떻게 작동하게 할 수 있나요?
답변1
수정된 스크립트:
for file in /home/pintolcv/Downloads/2014*D890.E.m; do
filepath=${file%/*}
filebasename=${file##*/}
#echo "File equals: $file"
#echo "File path equals: $filepath"
#echo "File basename equals: $filebasename"
if [[ -e "$file" ]]; then
echo "File Found: $filebasename - ${filebasename:5:3}"
mv "$file" "$filepath/IP.PMST.BHE..D.2014.${filebasename:5:3}"
else
echo "files do not exist"
fi
done