Saturday, May 18, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  27] [ 0]  / answers: 1 / hits: 11092  / 3 Years ago, mon, july 5, 2021, 7:22:19

I have two commands that I through were the same, but they don't share the same parameter:




  • time -f "%E %C" mycommandtomeasure

  • /usr/bin/time -f "%E %C" mycommandtomeasure



The first one does not execute, while the second one does. The first one cannot find the -f parameter. When checking whereis time I do get the path /usr/bin/time, so I understand it this way that time is the same command as /usr/bin/time.



Apparently, my assumption is wrong though. Could someone help me to elaborate?


More From » 16.04

 Answers
0

Let's have a look at what time actually is using the type command (see help type):



$ type -a time
time is a shell keyword
time is /usr/bin/time


So apparently, time on our system is both




  • a keyword directly built into your Bash shell

  • an executable file /usr/bin/time



Because shell keywords take precedence over executables, what you actually run when typing only time is the shell keyword. You also see that from the order in which type -a lists them, or from the output of just type time, which only lists the one effective type.



Now, let's check what each of those can do:




  • Executables usually have a manpage (manual page), which we can open and read using the man command, i.e. here man time.


  • To get help about stuff built into Bash, you have to use the help command: help time




You will note that the shell keyword supports less options than the executable, but it has other advantages, as you can e.g. time complex Bash constructs like pipelines with it. See the end of this answer for an example.



If you need to use the executable instead of the shell keyword though, you can either type the full path, i.e. /usr/bin/time, or you can prefix the command with a backslash to stop Bash from evaluating it: ime



By the way, while time is a shell keyword in Bash, it does not exist in sh (Dash), where you would only get the executable.




[#7694] Monday, July 5, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
restlerfin

Total Points: 347
Total Questions: 112
Total Answers: 108

Location: Ukraine
Member since Wed, Dec 16, 2020
3 Years ago
;