Below is some sort of pseudo-code for what I'm trying to accomplish:
#!/bin/bash
# I already have the variable below figured out (positive integer):
numlines=$([returns number of lines containing specific characters in a file])
# This is basically what I want to do with it:
for i in {1..$numlines}; do
# the part below is already figured out as well:
do some other stuff
done
I can execute it fine from the command line by inserting the actual number in the `{1..n}' sequence. I just need to know if it's possible to include a variable here and how to go about doing it.
- I have tried
export
ing it - I have tried putting the variable itself in curly braces inside the sequence:
{1..${numlines}}
- I have tried putting it in double-quotes hoping it would expand:
{1.."$numlines"}
- I have tried escaping the
$
:{1..\$numlines}
Do I need to use a set -[something]
command in order for this variable to get expanded? I have even tried some forms of using eval
...all to no avail.
I just need to know if there is something simple or obscure that I am missing or if this is even possible before I waste anymore time on it.
I could throw together a really, really hackish way of doing it to make it work as needed, but I'd like to avoid that if at all possible and learn the right way to go about doing it.