I have a file that contains a list of absolute paths of several files. I need to move all of the files listed in the file to another directory. Unfortunately, I have to do this using in-line shell scripting (i.e. sh -c), and I have no power over text passed outside of the quotation marks of the script (I'm using a software that passes the command as an in-line shell script to the OS).
$file in the following command evaluates to an empty string when using in-line scripting.
sh -c "while IFS= read -r file; do mv $file /target_dir; done < /source_dir/list_of_files.txt"
But if I enter the command in the terminal, everything works fine:
while IFS= read -r file; do mv "$file" /target_dir; done < /source_dir/list_of_files.txt
Is it possible to use read in an in-line shell script? If so, what am I doing wrong? I would like to avoid using bash file if possible, but I may not have that option.
OS:RedHat 8.7
list_of_files.txt
/home/usr1/file-16952.txt
/home/usr1/file-1825.txt
/home/usr1/file-2055.txt
/home/usr1/file-2165.txt
/home/usr1/file-2224.txt
/home/usr1/file-2452.txt
/home/usr1/file-4565.txt
/home/usr1/file-5763.txt
/home/usr1/file-8361.txt