anordal / shellharden

The corrective bash syntax highlighter
Mozilla Public License 2.0
4.63k stars 130 forks source link

Splitting strings into arrays #18

Closed ulrikrasmussen closed 6 years ago

ulrikrasmussen commented 6 years ago

Thank you for taking the time to write "Safe ways to do things in bash", this is extremely valuable information. I stumbled upon a surprising behavior in one of your suggestions.

The read-based method for splitting strings into arrays described here breaks in combination with set -e, since the return code of read is nonzero when it encounters end-of-file. I am not sure if I have a good suggestion for how to fix it, short of specifying a long unique string for the -d argument and appending it to the end of the printf format string, or putting the call to read within a compound expression.

Tested on Bash 4.4.19.

anordal commented 6 years ago

Thanks for reporting this!

A common workaround to get things working with set -e is to add || true to the end of the command. That worked.