Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • \$\begingroup\$ 1. I'd include -r in the byte count. 2. f()(while ... done) is a bit shorter. \$\endgroup\$ Commented Sep 24, 2015 at 6:36
  • \$\begingroup\$ @Dennis: Without [[ $r ]]&&, if N=4, an input line of length 4 will produce a blank output line where there wasn't one before. Because read returns a string of 4 chars, then sees a newline on the next call and returns right away. Also, thanks for the () tip. I didn't know you could define fns that way. \$\endgroup\$ Commented Sep 24, 2015 at 6:37
  • \$\begingroup\$ I recommend reading Tips for golfing in Bash. It's a great resource. \$\endgroup\$ Commented Sep 24, 2015 at 6:39
  • \$\begingroup\$ Actually, since while is already compound, you don't even need the parentheses: f()while ... done \$\endgroup\$ Commented Sep 24, 2015 at 6:42
  • \$\begingroup\$ @Dennis: wow, haxx. Thanks for the link. A couple of those things were new to me, and I fixed a couple things in another answer :) I don't normally golf, but >15 years of being a command-line junkie has taught me a thing or two :) \$\endgroup\$ Commented Sep 24, 2015 at 7:18