I am trying to copy files from one path to another path. I have a text file which has all names of files in the following pattern:
file-1.txt file-2.pdf file-3.ppt ....
I created a
.sh file with the following code:
#!/bin/bash file=`cat filenames.txt`; fromPath='/root/Backup/upload/'; toPath='/root/Desktop/custom/upload/'; for i in $file; do filePath=$fromPath$i #echo $filePath if [ -e $filePath ]; then echo $filePath yes | cp -rf $filePath $toPath else echo 'no files' fi done
The above code is copying only the last file name from the text instead of all to the destination path.