[Toybox] [PATCH] head -X
    enh 
    enh at google.com
       
    Mon Mar 16 21:16:00 PDT 2015
    
    
  
Allow "head -X" as well as "head -n X".
diff --git a/toys/posix/head.c b/toys/posix/head.c
index e8517d4..608b93a 100644
--- a/toys/posix/head.c
+++ b/toys/posix/head.c
@@ -4,7 +4,7 @@
  *
  * See http://opengroup.org/onlinepubs/9699919799/utilities/head.html
-USE_HEAD(NEWTOY(head, "n#<0=10", TOYFLAG_BIN))
+USE_HEAD(NEWTOY(head, "?n#<0=10", TOYFLAG_BIN))
 config HEAD
   bool "head"
@@ -50,5 +50,10 @@ static void do_head(int fd, char *name)
 void head_main(void)
 {
-  loopfiles(toys.optargs, do_head);
+  char **args = toys.optargs;
+  if (*args && **args == '-') {
+    TT.lines = xstrtol(*(args++) + 1, NULL, 10);
+    toys.optc--;
+  }
+  loopfiles(args, do_head);
 }
 1426565760.0
    
    
More information about the Toybox
mailing list