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

Since the article doesn't clarify on shell command priority, commands are search in order:

1. Alias expansion.

2. Defined shell functions.

3. Built-in shell functions.

4. Command path.

If you provide an unqualified command that matches more than one of these elements, the first match wins.

Prepending a backstroke: "\command", will inhibit alias expansion. E.g.:

    alias date="echo no date"
    date
    \date
Should return "no date", and your current system date, respectively.

To invoke a system command directly, call the full path. If you don't feel like running the fish shell (not that there's anything wrong with that).

Some simple shells (e.g., dash, and IIRC the original Bourne shell, though that is not what you'll find as /bin/sh on most modern systems) don't include a time builtin, and can invoke the system time command directly.




You can also use the 'command' built-in to skip aliases and shell functions.

$ command time --version GNU time 1.7


Perhaps, but time is a syntactic form, like `if` or `case`.

https://www.gnu.org/software/bash/manual/html_node/Pipelines...


I'm sorry, that's not clear to me. What's the significance exactly?


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.




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

Search: