bash - copy files from one path to another path in linux -
i new linux. trying copy files 1 path path. have text file has names of files in following pattern:
file-1.txt file-2.pdf file-3.ppt ....
i created .sh
file following code:
#!/bin/bash file=`cat filenames.txt`; frompath='/root/backup/upload/'; topath='/root/desktop/custom/upload/'; in $file; filepath=$frompath$i #echo $filepath if [ -e $filepath ]; echo $filepath yes | cp -rf $filepath $topath else echo 'no files' fi done
the above code copying last file name text instead of destination path.
please help.
the proper way loop on set of input lines is
while read i; : "$i" done <filenames.txt
note use of double quotes around "$i"
, variable interpolation string contains filename component. unquoted values appropriate when require shell word splitting , wildcard resolution.
Comments
Post a Comment