I would like to use the numeric value of the input argument that I pass to a bash script like this:
./script_pb3.sh out.txt 3
Here I would like to take the second argument that I pass (i.e. the value 3) and use it as a numeric value inside my script, that looks like this:
#!/bin/bash
NUM=$2
for i in {1..$NUM}; do
echo $i
done
But when I run it all I get is
{1..3}
Instead of
1
2
3
Can you please provide an explanation for why this is happening and a workaround? I think that this question aims at casting a string value to an integer value but I am not sure. Any help is greatly appreciated.
EDIT: the answer from here contains a debate concerning the answer to my issue (i.e. it assumes the answer is already known), but it does not come as an answer to my question, therefore I didn't find it in my first searches. Thank you, though, for pointing it out.