Wednesday, December 15, 2010

Korn shell - Time (built-in command)

In this and some later blogs about I will look into a couple of Korn shell features, I'm only interested in Korn-shell features for scripts though, not in the interactive usage.
Today my topic is the

Time (built-in command)

The built-in time command has a nice feature which distinguishes it from the system commands /bin/time or /bin/timex or the Bourne shell built-in time. (I didn't check other shells built-in time).

You cannot just run it with an external command but also with a function.

Example:
#!/bin/ksh
f() {
    sleep $1
}
time f 62
will report
real    1m2.01s
user    0m0.00s
sys     0m0.00s
Note: the space is a tab (not a sequence of spaces as in timex).

A little sed editing will get the output format closer to timex:
(time f 62) 2>&1 | sed '/^real/,/^sys/ {
# this is: tab zero m to be replaced by tab
s/ 0m/ /
# replace m by colon
s/m/:/
# remove trailing s
s/s$//
}'

but still not quite (timex runs e.g. on Solaris 10)
timex sleep 62

real        1:02.02
user           0.00
sys            0.00
In later posts I will look into coprocesses and job control.

3 comments:

  1. Big Data and Hadoop is an ecosystem of open source components that fundamentally changes the way enterprises store, process, and analyze data.

    hadoop training in bangalore

    ReplyDelete
  2. myTectra Amazon Web Services (AWS) certification training helps you to gain real time hands on experience on AWS. myTectra offers AWS training in Bangalore using classroom and AWS Online Training globally. AWS Training at myTectra delivered by the experienced professional who has atleast 4 years of relavent AWS experince and overall 8-15 years of IT experience. myTectra Offers AWS Training since 2013 and retained the positions of Top AWS Training Company in Bangalore and India.

    aws training in bangalore

    ReplyDelete
  3. Harvard Business Review named data scientist the "sexiest job of the 21st century".This Data Science course will cover the whole data life cycle ranging from Data Acquisition and Data Storage using R-Hadoop concepts, Applying modelling through R programming using Machine learning algorithms and illustrate impeccable Data Visualization by leveraging on 'R' capabilities.With companies across industries striving to bring their research and analysis (R&A) departments up to speed, the demand for qualified data scientists is rising.

    data science training in bangalore

    ReplyDelete