How do you iterate through a loop n amount of times when n is specified by the user at the beginning?I have written a shell script and need to repeat a certain part of it n numbers of times (depending upon how many times the user wishes).My script so far looks like this:echo how many times would you like to print Hello World?read numfor i in {1..$num}doecho Hello WorlddoneIf I change num to a number such as 5 the loop works however I need to be able to let the user specify the amount of times to iterate through the loop.
How do you create a for loop with a changeable number of iterations?
bash;shell script;for;loop device
You can use seqfor i in $(seq 1 $num) or your shell may support C-style loops e.g. in bashfor ((i=0; i<$num; i++))