Fix a bug in lines() (after a year of its discovery!)

Some time ago, about a year ago, i discovered a bug at `lines()` when incorporating it in a Shell library of mine.
Basically, when you ran for the first time, it stored a integer with the number of lines in the `${lines}` variable, which is the expect.
But, when you ran it for the second time, it started adding the value of `${lines}`, from the first run, with the value of the current run.

The fix to this is very simple, just add `unset` at the end of the function.
I had been wanting to do a pull request for a while to fix this, but i've ran out of time and ended up forgetting about it.

I hope it helps now.
This commit is contained in:
Luiz Antônio 2021-06-13 00:31:34 -03:00 committed by GitHub
parent cd6e426a50
commit daa7772ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -460,6 +460,7 @@ lines() {
done < "$1"
printf '%s\n' "$lines"
unset lines
}
```