Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Of the two C-shell aliases below, only the first prints the time command's report of elapsed time. How can I get the alias with the pipeline to also print the time report?

alias make1 'time make'

alias make2 'time make |& tee make.log'
share|improve this question
1  
@ArneStenström I approved the edit now – but please note that editing others' posts in such a radical way as proposed before (and now reflected in your comment) is not encouraged. Furthermore, you've already edited the question once. While I understand that you want to improve your posts more than once, please make your suggested edits count and only propose one. Thanks. – slhck Mar 12 '12 at 19:13
up vote 6 down vote accepted

The time command built-in to the C shell (csh or tcsh) doesn't work with pipelines. To avoid this limitation, use the standalone time command instead, which is usually found at /usr/bin/time (if it isn't, try whereis time to locate it).

Change time in your command-line to /usr/bin/time (or /usr/bin/time -p) or whatever the path to the time program is, and it should work.


Why it didn't work:

The C shell (like some other shells) has a built-in time command (see the builtin manual page), which is used in preference to the non-builtin (standalone) time program:

% which time
time: shell built-in command.
% 

and the man page for csh (actually tcsh on my system) states:

time [command]
   Executes command (which must be a simple command, not an alias,
   a pipeline, a command list or a parenthesized command list) ...

The /usr/bin/time command doesn't have this limitation, and neither do the inbuilt time commands of most other shells, for example bash or zsh.

share|improve this answer
    
where can I download non-csh time program? I've googled and it seems hard to find one. – Stan Mar 12 '12 at 15:09
    
Sorry, I thought /usr/bin/time is the built-in one and was trying to find another one. Thanks! – Stan Mar 12 '12 at 15:46

Did you mean to use a pipe there? What you're essentially doing is piping the result of the second time command into tee. That's why your result is not being printed out - it's actually probably being written into make.log.

share|improve this answer
    
it's not in the log either. I was wondering should I quote the command "make |& tee make.log"? – Stan Mar 12 '12 at 8:52
    
You should quote it as that's part of alias' syntax. Are you using BASH? – deed02392 Mar 12 '12 at 8:56
1  
c shell. I will try quote the inner command. – Stan Mar 12 '12 at 8:57
    
Have you tried just piping the output? I don't know about c shell but check you've re-logged in after changing an alias so it can be reloaded. – deed02392 Mar 12 '12 at 9:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .