I am attempting to write a function which will take two commands as inputs, time the executions of both of them, then output those times to a text file. After reading this post, I got most of the way there, and can write my execution times to a file one at a time. The problem I have now is getting the function to accept two multi-word inputs. My current code looks like:
timeDiff () {
{ time "$1" ; } 2> ~/file.txt
{ time "$2" ; } 2>> ~/file.txt
}
If I run these lines sequentially with the functions I want, everything is fine. The file is overwritten with the time info of the two functions. Here are some of the attempts and problems I have with this:
timeDiff grep "str" file1 query database lookup.sql
This will cause my file to have a warning on grep, some times, and a bash: str: command not found
.
timeDiff 'grep "str" file1' 'query database lookup.sql'
This will cause my file to have bash:grep "str" file1: No such file or directory, some times, and bash:query database lookup.sql: No such file or directory.
I think that this is related to how I need quotation marks for my grep, but perhaps there's a better way of writing the inputs for the functions. I'm a beginner, so I'm eager to learn! Thanks!