0

I would like to write a simple bash script that will allow me to create 5 text files called File1, File2, File3, File4 and File5 each populated with the text "F1", "F2", "F3", "F4" and "F5" respectively.

I have tried the script

for i in 1,2,3,4,5; do
echo "F"$i > File$i
done

But this creates one file called File1,2,3,4,5 with the text in it F1,2,3,4,5.

How do I correct this code?

Thank you very much

1
  • 1
    change 1,2,3,4,5 to 1 2 3 4 5 as it is being read as one string due to the IFS(internal field separator) being default(Whitespace,tab newline). Commented Jun 23, 2014 at 12:57

1 Answer 1

4

Try the below code to Print F1,F2,F3,F4,F5 into five different files File1,File2,File3,File4,File5 seperately.

for i in {1..5}; do echo "F"$i > File$i; done
  • {1..5} Represents the range from 1 to 5.

  • do echo "F"$i > File$i creates a file with the name as File$i and prints the value F$i to that file.(i represents the current value ranges from 1 to 5).

Sign up to request clarification or add additional context in comments.

Comments

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.