I have several different algorithms, that I need to prototype.
So I make prototype programs and a script.
the script called time.sh looks like this
echo "Timing algorithm1:"
time algo1 >dev/null
echo "Timing algorithm2:"
time algo2 >dev/null
echo "Timing algorithm3:"
time algo3 >dev/null
...
Now for simplicity sake substitute ls for algo1 ...
(I don't want to post code for each algorithm, force people to compile it ...)
echo " Timing ls"
time ls 2>&1 > /dev/null
call it time_ls.sh
then I do
sh time_ls.sh > ls_sh.meas
No matter what I do, whatever redirections I place in the script or commandline, I get one of two results. Either I get the output of echo ie "Timing ls" in the terminal and the timing data in ls_sh.meas or the opposite.
It's like the stdout and stderr don't want to get together and make one baby data file.
Can anyone explain this weird behaviour, and suggest a work around?
PS: This is in done in bash.
/usr/bin/timeis a more flexible, more configurable tool than thebashbuiltintimethat you're using. Seeman timeandtype -a time. Seeman bashabout thetimebuiltin. It explains redirectingtime.There's information about redirection inman bash. – waltinator Aug 13 '23 at 06:02shto do the work – Chris Davies Aug 13 '23 at 09:59time pipelineconstruct is run as in{ time pipeline; } 2>&1 | tee ...– Stéphane Chazelas Aug 14 '23 at 18:33