Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am expecting the output of the 'time' command to be saved to the variable, but only seems to save the output of the 'ping' command, and the output of the 'time' command escapes to the console and is displayed. Similarly, if I try a different command, such as 'clock', it saves clock's output, not time's. i.e.
[user@linux user]# TESTTIME=$( time -f '%e' clock )
[user@linux user]# echo $TESTTIME
Mon Jan 27 17:35:09 2003 -0.087824 seconds
What I want to be saved to TESTTIME there is '0.09', but alas no.
I can't think of the syntax to get the right output saved. Any help appreciated.
the time you're invoking is the bash builtin. I'm not sure how you'd trap that output. man time will tell you about the program in /usr/bin/time, which is probably what you want, and that will write the output of it to stdout.
thanks unspawn, I tried that before, but the output STILL goes to the console, and the variable is left empty!
I've also tried various other combinations but can never seem to trap or redirect time's output - it seems to get to the console whatever I do. If it won't work this way, is there any other way to find out the elapsed time to run a command (other than writing a small C/C++ program)?
The greps are just to remove the output from ping, and the -o
/dev/stdout option to time is the only way to get time to output to
STDOUT instead of STDERR. . . There is still an issue with a
newline in the resulting variable, but I'm sure you can deal with
it. . .
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
If you are worried about milisecond accounting, you might check into
whether or not time is counting all the greps. . . I haven't bothered, as
it doesn't take a lot of time, but it may throw off your statistics a bit.