r/tinycode • u/thefebs • Dec 12 '12
Shortest useful code
What's the most useful program you can imagine using five lines of code or less? Language is your choice. Describe the function of the program and include the code, if you please.
27
Upvotes
6
u/chrisdown Dec 13 '12 edited Dec 13 '12
A few problems:
functionisn't POSIX;Leading/traililng/consecutive whitespace will get mangled;
Backslash escape sequences are being interpreted;
If the line starts with a dash,
echocould interpret it as an option and break;If the file's final character is not a newline, the last line will not be printed;
If the filename contains any whitespace, this will break.
Here's a version with these issues fixed:
Note also that as a consequence of using bash using cstrings internally, any variables containing a null will be truncated to the position of that null.