I need to read a text file line by line and store the results in an array. My current function works in newer Bash versions by using a variable name passed as an argument, but it relies on array features that are unavailable on macOS's default Bash 3.2. I also ran into problems with backslashes and other escaped characters being altered, apparently because of eval. What is the safest way to preserve each line exactly while remaining compatible with Bash 3.2?
1 Answer
The simplest solution may be to install a current Bash through a package manager such as Homebrew or MacPorts. The system Bash on older macOS releases is 3.2, so newer array conveniences are unavailable. Once a recent Bash is used, the original function works as expected.

That is what I ended up doing. After installing a newer Bash, the function started behaving correctly without changing the file contents.