Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • Do you want to output the elapsed time, or do you need to do more with it? Would time be good enough? See How to get execution time of a script effectively? and How to measure time of program execution and store that inside a variable. Commented Nov 21, 2022 at 9:33
  • I need to (correctly) wrap each command to output, among others (e.g. some prologue / epilogue), elapsed time. I don't know how to achieve such wrapping and to satisfy "Don't put code inside variables!" rule (see BashFAQ #50). Commented Nov 21, 2022 at 10:39
  • 1
    That's an XY problem - you think you need to "wrap" each command, but why do you need to wrap anything at all? What goal do you think you'll accomplish by this wrapping? Commented Nov 21, 2022 at 11:10
  • @muru At least: 1) measuring of elapsed time, 2) checking of exit status, 3) logging command's start and finish. W/o wrapping the 1), 2), 3) need to be done manually for each command leading to code duplicates. Commented Nov 21, 2022 at 12:27
  • In that case, what's the expected result for something like cmd1 | cmd2 or while cmd1; do cmd2; done? 1, 2 and 3 for each of cmd1 and cmd2 or 1, 2 and 3 for the whole construct? Commented Nov 21, 2022 at 12:51