#/------------------------------ for … in … : go through the list supplied after
#| the "in" one by one, setting the variable
#| specified after the "for" to each element from
#| the list, in turn
#|
#| /----------------------- original: name of variable to set to each value
#| |
#| | /----------- */file.txt: the list of all "foldername/list.txt"
#| | |
#| /------\ /--------\
for original in */file.txt ; do
folder_only="${original%/file.txt}"
#\--------/ \-------------------/
# | |
# | \------------ become the value of "original", but cut off
# | any "/file.txt" from the end; for example:
# | "folder1/file.txt" becomes "folder1"
# |
# \------------------------------ save the result in a variable that's called
# "folder_only"
cp "${original}" "${folder_only}/${folder_only}.txt"
done
more annotations to comeor, without the explanations:
for original in */file.txt ; do
folder_only="${original%/file.txt}"
cp "${original}" "${folder_only}/${folder_only}.txt"
done