Roberto C. Sanchez wrote:
On Thu, Oct 12, 2006 at 08:51:29PM -0400, José Alburquerque wrote:
I guess I could do that, it's just that I use certain commands almost
"instinctively" and sometimes I forget. A lot of times I'm running
certain processes one after the other in several shells. It is after
I've run them that I realize that it would have been nice to "time" some
of them.
I suppose I could just be more attentive as to which commands I'd like
to "time". I'll keep what you say in mind. :-)
If it is always the same commands, then consider setting them to use the
time command as an alias.
For example, if you always want to know how long a dd took, then use
something like `alias dd='/usr/bin/time /usr/bin/dd'`.
Of course, you will need to use dd and not /usr/bin/dd to get the
benefit. Additionally, if you set your alias like this: `alias
dd='/usr/bin/time dd'`, then it will recurse and bad things will happen.
Trust me on this :-)
I once did `alias mutt='LANG= mutt'` and when I executed it, I had to
reboot the machine to get it to quit.
Regards,
-Roberto
I will agree that, if you only have a few commands that you regularly
want timed, then an alias is probably the easiest way to do it.
I have the following alias: alias pr='pr -F -l 59', and it works just
fine, no recursion at all. I just checked 'man bash' and this is what
it says:
ALIASES
Aliases allow a string to be substituted for a word when it is
used as
the first word of a simple command. The shell maintains a
list of
aliases that may be set and unset with the alias and unalias
builtin
commands (see SHELL BUILTIN COMMANDS below). The first word
of each
command, if unquoted, is checked to see if it has an alias.
If so,
that word is replaced by the text of the alias. The alias name
and the
replacement text may contain any valid shell input,
including the
metacharacters listed above, with the exception that the alias
name may
not contain =. The first word of the replacement text is
tested for
aliases, but a word that is identical to an alias being expanded
is not
expanded a second time. This means that one may alias ls to ls
-F, for
instance, and bash does not try to recursively expand the
replacement
text. If the last character of the alias value is a blank,
then the
next command word following the alias is also checked for alias
expan-
sion.
Aliases are created and listed with the alias command, and
removed with
the unalias command.
So I'm don't see what could have caused the recursion Roberto mentioned,
unless that was some time ago and the behavior of 'alias' has changed.
At any rate, it should be safe to use the command name as an alias and
run time from within the replacement text, as in:
alias command='time command'
In fact, I just tested alias ls='time ls' and it worked just fine.
--
Marc Shapiro
No boom today. Boom tomorrow. There's always a boom tomorrow.
What?! Look, somebody's got to have some damn perspective around here.
Boom. Sooner or later ... boom!
- Susan Ivanova: B5 - Grail
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]