1

A newbie so please excuse

I use the below script to create copies of the same file

for i in {1..5}
 do 
  cp file xfs/file$i
 done

To create

file1 file2 file3 file4 file5

My Question is if i wanted to dictate how many files are created how do i do this

I have tried

read -p "How many files do you want" num

for i in {1..$num}
 do 
  cp file xfs/file$i
 done

I'm unsure on how to get the "for" command top accept my variable

Any ideas

fzzle
  • 1,466
  • 5
  • 23
  • 28
Phill
  • 11
  • 1
  • 2

1 Answers1

0
#!/bin/bash
for (( i=1; i<=$num; i++ )); 
    do 
        echo $i; 
done

http://www.cyberciti.biz/faq/bash-for-loop/

rgunning
  • 568
  • 2
  • 16