Just "${f1%}"
doesn't do anything useful; you want to put a pattern for something to actually remove after the %
; and of course you probably want to remove a suffix from f
, not from f1
. (Giving your variables sensible names also helps.)
It's not clear what you expect $2
and $3
to contain, but they probably won't work correctly after you cd $1
(and all three of these should be quoted anyway).
Guessing a bit as to what you actually want, try this:
#!/bin/sh
d=$(date +'%F%H:%M)
for f in "$1"/*.xml
do
# Trim directory prefix
b=${f#$1/}
# Trim .xml suffix
b=${b%.xml}
# Copy
cp -v "$f" "$2/$b$d".xml
cp -v "$f" "$3/$b$d".xml
done
There are no Bashisms here so I put a /bin/sh
shebang on this.