how to use a variable in head function in for loop in unix shell

shell, unix

Solution

What about something like this:

for ((i=1; i<6; i++))
do
    head -n$i test.txt
done

Notice that I've started the variable `i` at `1` so that we don't get an error from `head` (like: `head: illegal line count -- 0`). And you can access the `i` variable by using `$i` in your loop.

Problem

i'm very new, and am working on variables. i wonder how can I use a variable in head function for example, ``` for ((i=0; i<5; i++)) head -((1+i)) test.txt ``` but it displays an error. how can i fix this?

Original source