Reputation: 31
I am trying to create a copy and rename files script. Here is what I have so far.
read COPYDIR
read DESTINATION
for file in `ls $COPYDIR`;do
if [ -f $COPYDIR/$file ]; then
cp $file $DESTINATION
fi
done
I'm trying to add a .bak extension to the files that are copied. How can I add this to the script?
Upvotes: 0
Views: 65
Reputation: 785186
You don't need to parse ls's output. You can do:
for file in "$COPYDIR"/*; do
f="${file##*/}"
[[ -f "$file" ]] && cp "$file" "$BAK_DEST_DIR1/$f.bak"
done
Upvotes: 1