I would like to apply a commands to files in a directory, target_dir, by the following code.
for t_file in $(find 'target_dir' -maxdepth 1 -type f);
do
exec {fd}<'command_list.txt'
while read -u "${fd}" eval_command
do
eval "${eval_command}"
done
exec {fd}>&-
done
A example of command_list.txt is
# command_list.txt
cat "${t_file}"
The program loads the command_file.txt for every files but I expects that it is more efficient if I can move the file pointer back to the first line of the file without needing to close and reopen it between iterations.
exec {fd}<'command_list.txt'
for t_file in $(find 'target_dir' -maxdepth 1 -type f);
do
(move cursor of read to the first line of 'command_list.txt')
while read -u "${fd}" eval_command
do
eval "${eval_command}"
done
done
exec {fd}>&-
Is seeking a file pointer back to the beginning of a file without reopening it possible in bash?