{"id":382,"date":"2019-02-27T16:40:04","date_gmt":"2019-02-27T16:40:04","guid":{"rendered":"https:\/\/jan.schnasse.org\/blog\/?p=382"},"modified":"2026-09-28T11:39:16","modified_gmt":"2026-09-28T09:39:16","slug":"a-stopwatch-in-bash","status":"publish","type":"post","link":"https:\/\/jan.schnasse.org\/blog\/2019\/02\/27\/a-stopwatch-in-bash\/","title":{"rendered":"A stopwatch in bash"},"content":{"rendered":"<p>Is it possible to implement a stopwatch in bash? Here is my try:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-383 size-full\" src=\"https:\/\/jan.schnasse.org\/blog\/wp-content\/uploads\/2019\/02\/stopwatch.gif\" alt=\"\" width=\"1179\" height=\"792\" \/><\/p>\n<p><a href=\"https:\/\/github.com\/jschnasse\/stopwatch\/blob\/master\/stopwatch\">https:\/\/github.com\/jschnasse\/stopwatch\/blob\/master\/stopwatch<\/a><\/p>\n<p>The script uses some interesting features like:<\/p>\n<ol>\n<li>\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">read -s -t.1 -n1 c <\/code> to read exactly one character (-n1) into a variable c only waiting 0.1 seconds for user input.<\/li>\n<li><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">sleep .1<\/code> to delay further processing for 0.1 seconds<\/li>\n<li><code class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">secs=$(printf \"%1d\\n\" ${input: 0 : -9})<\/code>Create a digit from all but the last 9 characters lead by a zero if string is empty. This is used to separate seconds from a nano seconds.&nbsp;<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Is it possible to implement a stopwatch in bash? Here is my try: https:\/\/github.com\/jschnasse\/stopwatch\/blob\/master\/stopwatch The script uses some interesting features like: \u00a0read -s -t.1 -n1 c to read exactly one character (-n1) into a variable c only waiting 0.1 seconds for user input. sleep .1 to delay further processing for 0.1 seconds secs=$(printf &#8222;%1d\\n&#8220; ${input: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,15],"tags":[],"class_list":["post-382","post","type-post","status-publish","format-standard","hentry","category-admin","category-software"],"_links":{"self":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/382","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/comments?post=382"}],"version-history":[{"count":1,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions"}],"predecessor-version":[{"id":4383,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/382\/revisions\/4383"}],"wp:attachment":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/media?parent=382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/categories?post=382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/tags?post=382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}