-1

How to make txt file in every folder that I made with while do loop in bash programming? There must be a text inside the file.

Here's the syntax to make folder with while do :

 #!/bin/bash

 COUNTER=1

 while [  $COUNTER -le 10 ]; do

 mkdir folder_$COUNTER

 let COUNTER=$COUNTER+1

 done
  • just .txt files, like when you make txt file with nano in terminal.. ... ah.. maybe we use echo and > .. like in this link https://unix.stackexchange.com/questions/159672/how-to-create-a-simple-txt-text-file-using-terminal but how do i place it so it can make every folder has each file txt? – sandimorinaga Sep 11 '17 at 16:06
  • can't you just add the command something like `echo 'some text' > folder_$COUNTER/textfile.txt` in the loop, just after having created your folder ? – Pac0 Sep 11 '17 at 18:10

1 Answers1

0
#!/bin/bash

 COUNTER=1

 while [  $COUNTER -le 10 ]; do

 mkdir folder_$COUNTER;
 cat text_file.txt > folder_$COUNTER/file_${COUNTER}.txt;

 let COUNTER=$COUNTER+1

 done
djadk
  • 74
  • 1
  • 3