Here are two examples that use while
loop.
In the next example, the content of the file called list
will be redirected to the while
loop, where each line will be read
as value of the variable $FILE_NAME
, that will be used as an argument in the mv
command.
while IFS= read -r FILE_NAME; do mv "$FILE_NAME" "/dest/dir/"; done < /path/to/list
In the next example, the command cat
will output the content of the file called list
. The output will be piped to the while
loop, where each line will be read
as value of the variable $FILE_NAME
, that will be used as an argument in the mv
command.
cat /path/to/list | while IFS= read -r FILE_NAME; do mv "$FILE_NAME" "/dest/dir/"; done
IMO using redirection is the better way. Here is provided more detailed explanation abut this usage of while
: While loop only processes the first entry of ssh command.