Skip to main content
added 6 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
#/------------------------------ 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/listfile.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
#/------------------------------ 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
#/------------------------------ 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/file.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
added 6 characters in body
Source Link
Stéphane Chazelas
  • 584.6k
  • 96
  • 1.1k
  • 1.7k
#/------------------------------ 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
for original in */file.txt ; do
  folder_only="${original%/file.txt}"
  cp -- "${original}" "${folder_only}/${folder_only}.txt"
done
#/------------------------------ 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
for original in */file.txt ; do
  folder_only="${original%/file.txt}"
  cp "${original}" "${folder_only}/${folder_only}.txt"
done
#/------------------------------ 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
for original in */file.txt ; do
  folder_only="${original%/file.txt}"
  cp -- "${original}" "${folder_only}/${folder_only}.txt"
done
added 1138 characters in body
Source Link
Marcus Müller
  • 51.5k
  • 4
  • 79
  • 121
#/------------------------------ 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
#
for original in */file.txt ; do
  folder_only="${original%/file.txt}"
  cp "${original}" "${folder_only}/${folder_only}.txt"
done

more annotations to come

#/------------------------------ 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

or, without the explanations:

for original in */file.txt ; do
  folder_only="${original%/file.txt}"
  cp "${original}" "${folder_only}/${folder_only}.txt"
done
Source Link
Marcus Müller
  • 51.5k
  • 4
  • 79
  • 121
Loading