shermanm | welp, the final answer seems to be that if the "source-repository-$something" file isn't terminated with a newline, the final line of the file is skipped, or, if only one line is present, the whole thing is skipped | 13:00 |
---|---|---|
clarkb | oh thats good to know but also your editor should always add a newline :) | 15:02 |
* clarkb has used vim for years and it does so automatically and its easy to forget not every editor does so | 15:03 | |
clarkb | in bash `help read` does show that by default the delimiter is newline and it reads until the delimiter | 15:20 |
clarkb | so that is documented behavior of the underlying implementation | 15:20 |
clarkb | looks like you can use readline to read the line and that treats EOF as newline on a non empty input | 15:22 |
clarkb | shermanm: if you're up to it maybe you want to test updating https://opendev.org/openstack/diskimage-builder/src/commit/02a3c8755960f0e1851da5ec0f8d4b66aee06494/diskimage_builder/elements/source-repositories/extra-data.d/98-source-repositories#L45 to `while read -e line; do` and see if that works for your original case | 15:22 |
clarkb | shermanm: if that does work I'd +2 a patch that does that (-e is the use readline flag) | 15:23 |
shermanm | ah! I made a bug report and included a different fix actually, adding `while read line || [ -n "$line" ]; do` : https://bugs.launchpad.net/diskimage-builder/+bug/2086192 | 15:26 |
shermanm | it looks like `-e` still returns nonzero if there's no trailing newline | 15:26 |
shermanm | but I'm happy to submit a patch as well | 15:26 |
clarkb | shermanm: if you get an EOF it should return non zero so that the loop exits | 15:27 |
JayF | yeah that fix looks strange to me | 15:27 |
clarkb | I think that is correct behavior we just want it to treat that as a newline for purposes of returning a line | 15:27 |
clarkb | oh but we need do while I guess | 15:28 |
shermanm | the issue, from what I can find, is that if the last line isn't terminated with a newline, `read` both returns a value, and exits nonzero | 15:28 |
clarkb | got it and readline would do the same thing (I wonder why they list that as an alternative) | 15:29 |
shermanm | this led me to a whole rabbit hole of stackoverflow posts, mostly of the theme "'while read line; do' considered harmful", so I'm not sure there's a clean looking fix | 15:30 |
shermanm | otoh, just loudly exiting if the source file isn't newline terminated would also be fine for me | 15:30 |
clarkb | ya and maybe add a note in the readme for the element that the input must end on a newline | 15:30 |
Generated by irclog2html.py 2.17.3 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!