Skip to content
Advertisement

create multiple file with content in linux with user input

I’m new in bash scripting and I’m trying to create a bash script which can create multiple file with content (around 10000 lines [no matters what text]) but with user input. I made a script which create files (see below) but how can I fill each file with 10000 lines? Thank you in advance!

#!/bin/bash
echo How many files do you want to create?
read numberOfFiles
echo
echo Please enter the files name with should start:
read nameForFiles
echo

for i in $(seq 1 $numberOfFiles)
do
        touch $nameForFiles-$i.txt
done

Advertisement

Answer

Replace your touch command with this:

for ((j=0; j<9999; j++)); do echo "Cyrus was here"; done > "$nameForFiles-$i.txt"
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement