Skip to main content

Timeline for answer to How to find line with least characters by yaegashi

Current License: CC BY-SA 3.0

Post Revisions

15 events
when toggle format what by license comment
S Jul 23, 2015 at 12:13 history suggested Evgeny CC BY-SA 3.0
Fix problem with `no newline at end of file `. (i.e. `printf "a" | this_script` prints a). Add note about NULLs
Jul 23, 2015 at 11:50 review Suggested edits
S Jul 23, 2015 at 12:13
S Jul 23, 2015 at 9:45 history suggested Evgeny CC BY-SA 3.0
Add note about 'no newline at end of file'
Jul 23, 2015 at 9:29 review Suggested edits
S Jul 23, 2015 at 9:45
S Jul 23, 2015 at 8:58 history suggested Evgeny CC BY-SA 3.0
Fix for empty input (prev version prints '\n'), fix for empty lines (prev version prints 'a\n' for input 'a\n\n'), change echo to printf (fix for `-n` and other strange strings)
Jul 23, 2015 at 8:21 review Suggested edits
S Jul 23, 2015 at 8:58
Jun 5, 2015 at 1:18 comment added yaegashi Thank you all for the comments and upvotes (some of the rep should go to @cuonglm for correcting my answer). Generally I don't recommend others to daily practice pure shell scripting but that skill can be found very useful in some extreme conditions where nothing other than static linked /bin/sh is available. It's happened to me several times with SunOS4 hosts with /usr lost or some .so damaged, and now in modern Linux age I still occasionally encounter similar situations with embedded systems or initrd of boot failing systems. BusyBox is one of the great things we recently acquired.
Jun 4, 2015 at 21:27 comment added Stéphane Chazelas See Why is using a shell loop to process text considered bad practice?
Jun 4, 2015 at 21:11 comment added Digital Trauma @mikeserv Yes I hadn't considered possible effects of $IFS
Jun 4, 2015 at 20:58 comment added mikeserv @DigitalTrauma - an expanded contiguous string of digits is not any more or less exempt from the conditions which make shell-quoting necessary than any other expanded string. $IFS is not digit-discriminatory - even if there are none in a default $IFS value, though many shells will accept a preset environment configuration for $IFS - and so that is not a particularly reliable default.
Jun 4, 2015 at 20:10 comment added mikeserv Have you tried benching your no exec! solution versus others which do? Here's a comparison of the performance differences between exec! and no exec! solutions for a similar problem. execing a separate process is very seldom advantageous when it spiders - in forms like var=$(get data) because it restricts the data flow to a single context - but when you move data through a pipeline - in a stream - each applied exec is generally helpful - because it enables specialized application of modular programs only where necessary.
Jun 4, 2015 at 18:54 comment added Digital Trauma (( ${#a} < ${#min} )) is possibly cleaner than [ "${#a}" -lt "${#min}" ]. Its unusual, but in this case the double quotes around the string length expansions are not necessary - string length will always be a contiguous string of digits.
Jun 4, 2015 at 12:08 comment added orion This really is the purest. Although, the clumsiness of tests in bash would convince me to pipe an intermediate result into sort instead.
Jun 3, 2015 at 7:51 history edited cuonglm CC BY-SA 3.0
added 17 characters in body
Jun 3, 2015 at 7:46 history answered yaegashi CC BY-SA 3.0