Hacker News new | past | comments | ask | show | jobs | submit login

A command takes a series of arguments, stdin/out/err pipes and returns an error code on completion.

time prefixes a pipeline ( the most basic case being a single command without a pipe into another ), a command block { ... } a subshell block ( ... ), a for statement, an if statement, just whatever really.

This "time" would output how long "a" took to run:

    /usr/bin/time a b c | { d e ; f g ; } | h i ;
This "time" outputs how long the pipeline "a", "d", "f", and "h" took to run:

    time a b c | { d e ; f g ; } | h i ; 
This is a syntax error:

    /usr/bin/time { d e ; f g ; }
This returns how long the command group takes to run:

    time { d e ; f g ; }
Further examples:

    $ time sleep 10 | sleep 1 ;
    
    real	0m10.073s
    user	0m0.000s
    sys	0m0.000s
    $ time sleep 1 | sleep 10 ;
    
    real	0m10.003s
    user	0m0.000s
    sys	0m0.000s
    $ /usr/bin/time sleep 10 | sleep 1 ;
    0.00user 0.00system 0:10.00elapsed 0%CPU (0avgtext+0avgdata 1796maxresident)k
    0inputs+0outputs (0major+80minor)pagefaults 0swaps
    $ 
    $ /usr/bin/time sleep 1 | sleep 10 ;
    0.00user 0.00system 0:01.00elapsed 0%CPU (0avgtext+0avgdata 1808maxresident)k
    0inputs+0outputs (0major+82minor)pagefaults 0swaps
Note the two /usr/bin/time's output their timing information as soon as the first command is done, but the pipeline doesn't return until both commands have exited.

> hope this rant helps in some way




Thanks, that does raise some interesting points.

What of:

    /usr/bin/time ( sleep 1 | sleep 10 )
Explicitly invvoking a subshell. Which I understand the builtin to be doing.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: