1

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

2 Answers 2

2

Replace your touch command with this:

for ((j=0; j<9999; j++)); do echo "Cyrus was here"; done > "$nameForFiles-$i.txt"
Sign up to request clarification or add additional context in comments.

Comments

2
#!/usr/bin/env bash

read -rp "How many files do you want to create? " numberOfFiles
echo
read -rp "Please enter the file name: " nameForFiles
echo

for ((n=1;n<=numberOfFiles;n++)); do
    for i in {1..1000}; do
        echo "line $i" >> "${nameForFiles}"-"${n}".txt
    done
done

2 Comments

for ((i=1; i<=1000; i++)) would be preferable over having to expand {1..1000} into a list of 1000 numbers before iteration begins.
thank you too for answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.