Requires trailing newline? #37

gwern opened this Issue Nov 16, 2011 · 1 comment


None yet
2 participants

gwern commented Nov 16, 2011

This is a tricky issue. I was going through the wiki page of examples and the readme, to remove all the tr munging now that we do '[:space:]' inside spark itself, when I discovered they weren't working! A stdin problem? But when I took the examples' output and manually echoed them in, spark worked! Huh?

$ echo -n 1,2, | spark && echo true


$ echo 1,2, | spark && echo true

I messed around and found that echo -n did cause the failure. After some more digging and use of set -x and tee, I found that spark was bombing out with an error at line 148, with read. If you do help read you find it demands a newline at the end of the input, or at least that its caller specify an end-of-input delimiter. We can't really do that because the last character will usually be a number we want! So I went to #bash and asked for help. It turns out that set -e is the problem - read is populating the array as we want it to, but then it reaches the end of input, returns a bad exit code, and per the arcane ad hoc rules governing it ( that kills the script. Or something like that. Bash example (note which one prints out):

$ echo -n 3,4, | { read var && echo true1; echo "$var"; } && echo true2

Removing set -e fixes the problem. The FAQ says 'GreyCat's personal recommendation is simple: don't use set -e. Add your own error checking instead.' so hopefully that wouldn't be too big an issue.

@gwern gwern added a commit to gwern/spark that referenced this issue Nov 16, 2011

@gwern gwern rm 'set -e' & quote per Riviera's advice; 'set -e' breaks on no trail…
…ing newline (see issue #37 for detailed discussion)

holman commented Nov 16, 2011

This is great work. Merged it in. Thanks so much for digging way way into this for me. I noticed something had broken it earlier but was too busy to actually dive in and see what the problem was.


holman closed this Nov 16, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment