0
#!/bin/bash
for i in {1..$1}; do echo 'for the love of god please work'; done

but

$ ./xgen2 5

does not print 'for the love of god please work' 5 times, it prints it once

please 'for the love of god-' please help

2 Answers2

3

You don't need eval

#! /bin/bash

for _ in $(seq $1)
do
    echo 'for the love of god please work'
done
Diego Torres Milano
  • 61,192
  • 8
  • 106
  • 129
0

try

for i in $(eval echo {1..$1}); do echo 'for the love of god please work'; done

this will evaluate $1 using eval and then utilize that value.

edit: if you don't want to eval, another option is: for i in {$(seq 1 $1)}; do echo 'for the love of god please work'; done

  • I'd like to add that using eval is not the best solution for various reasons, another way to create the range is like this: `for i in $(eval echo {1..$1}); do echo 'for the love of god please work'; done` – Mitchell Dzurick Nov 05 '20 at 01:25