dylanaraps / pure-sh-bible

📖 A collection of pure POSIX sh alternatives to external processes.
MIT License
6.45k stars 281 forks source link

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

Closed takusuman closed 3 years ago

takusuman commented 3 years ago

Some time ago, about a year ago, i've discovered a bug at lines() when incorporating it in a Shell library of mine. Basically, when you ran it for the first time, it stored a integer with the number of lines in the ${lines} variable, which is the expected. 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, so it removes the old value from the memory and them add the new.

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.

dylanaraps commented 3 years ago

Yes. These aren't meant to be copy/pasted into projects 1:1. They're meant to be examples. Thanks for the PR.