Skip to main content
added 229 characters in body
Source Link
Andy Dalton
  • 14.7k
  • 1
  • 29
  • 50

I'm not totally sure what you're asking. Do you want to supply a parameter, and loop over the values from 1 to that value? If so, you can do this with bash (and probably other shells as well:

function test() {
    for ((i = 1; i <= $1; ++i)); do
        echo $i
    done
}

test 12
1
2
3
4
5
6
7
8
9
10
11
12

If you don't have a shell that supports the for(...) syntax, you can do the same thing with:

function test() {
    i=1

    while [ $i -le $1 ]; do
        echo $i
        i=$(expr $i + 1)
    done
}

I'm not totally sure what you're asking. Do you want to supply a parameter, and loop over the values from 1 to that value? If so, you can do this with bash (and probably other shells as well:

function test() {
    for ((i = 1; i <= $1; ++i)); do
        echo $i
    done
}

test 12
1
2
3
4
5
6
7
8
9
10
11
12

I'm not totally sure what you're asking. Do you want to supply a parameter, and loop over the values from 1 to that value? If so, you can do this with bash (and probably other shells as well:

function test() {
    for ((i = 1; i <= $1; ++i)); do
        echo $i
    done
}

test 12
1
2
3
4
5
6
7
8
9
10
11
12

If you don't have a shell that supports the for(...) syntax, you can do the same thing with:

function test() {
    i=1

    while [ $i -le $1 ]; do
        echo $i
        i=$(expr $i + 1)
    done
}
Source Link
Andy Dalton
  • 14.7k
  • 1
  • 29
  • 50

I'm not totally sure what you're asking. Do you want to supply a parameter, and loop over the values from 1 to that value? If so, you can do this with bash (and probably other shells as well:

function test() {
    for ((i = 1; i <= $1; ++i)); do
        echo $i
    done
}

test 12
1
2
3
4
5
6
7
8
9
10
11
12