How to escape characters like colon : and comma , in for loop?

284 Views Asked by At

I have a file named "blocked.txt" which contains name of 4000 files like below:

1502146676.VdeI4b5c5cbM804631.vps47619.domain.local:2,
1502146676.VdeI4b5c5cdM808282.vps47619.domain.local:2,
1502146677.VdeI4b5c5d3M192892.vps47619.domain.local:2,
1502146677.VdeI4b5c5d7M213070.vps47619.domain.local:2,
1502146677.VdeI4b5c5e5M796312.vps47619.domain.local:2,
1502146678.VdeI4b5c5efM412992.vps47619.domain.local:2,
1502146678.VdeI4b5c5f1M613275.vps47619.domain.local:2,
1502146679.VdeI4b5c5f8M11301.vps47619.domain.local:2,
1502146682.VdeI4b5c66dM115848.vps47619.domain.local:2,S
1502146682.VdeI4b5c676M608733.vps47619.domain.local:2,
1502146685.VdeI4b5c69aM1652.vps47619.domain.local:2,
....
 ....

i ran below command on shell to copy the files to /tmp/backup directory

for i in `cat blocked.txt`; do cp -f  "${i}" /tmp/backup/ ; done 

but this gives me error "do you want to overwrite ? y/n" even though i have used -f with cp

Any idea whats wrong in the command ?

1

There are 1 best solutions below

0
On

You likely have an alias,

alias cp="cp -i"

or function

cp () {
    command cp -i "$@"
}

that interferes.

To solve this, simply use command cp instead of just cp:

while read -r name; do
    command cp "$name" /tmp/backup
done <blocked.txt

Or specify the full path to cp:

while read -r name; do
    /bin/cp "$name" /tmp/backup
done <blocked.txt