[英]bash script to rename following a pattern in subdirectories and make a copy
[英]Copy and Rename script in Bash
我正在嘗試創建一個副本並重命名文件腳本。 這是我到目前為止所擁有的。
read COPYDIR
read DESTINATION
for file in `ls $COPYDIR`;do
if [ -f $COPYDIR/$file ]; then
cp $file $DESTINATION
fi
done
我正在嘗試向復制的文件添加.bak擴展名。 如何將其添加到腳本中?
您不需要解析ls的輸出。 你可以做:
for file in "$COPYDIR"/*; do
f="${file##*/}"
[[ -f "$file" ]] && cp "$file" "$BAK_DEST_DIR1/$f.bak"
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.