diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-05-28 17:57:46 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-05-28 17:57:46 +0200 |
| commit | 048c9b2a7d0ddf252667fa7cfff87cbf4acfd48a (patch) | |
| tree | 90e48a3fc5c272f92c0172f2199ecf61d5b01205 /content | |
| parent | ad2f788d90e90b734dab978ff58f4a65e3f1fdcc (diff) | |
| download | mitjafelicijan.com-048c9b2a7d0ddf252667fa7cfff87cbf4acfd48a.tar.gz | |
Note: Measure time took
Diffstat (limited to 'content')
| -rw-r--r-- | content/notes/easy-time-took-in-bash.md | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/content/notes/easy-time-took-in-bash.md b/content/notes/easy-time-took-in-bash.md new file mode 100644 index 0000000..c97f0f1 --- /dev/null +++ b/content/notes/easy-time-took-in-bash.md | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | --- | ||
| 2 | title: "Easy meassure time took in a bash script" | ||
| 3 | url: easy-time-took-in-bash.html | ||
| 4 | date: 2023-05-28T17:53:20+02:00 | ||
| 5 | type: notes | ||
| 6 | draft: false | ||
| 7 | tags: [bash] | ||
| 8 | --- | ||
| 9 | |||
| 10 | In Bash, the $SECONDS variable is a special variable that automatically keeps track of the number of seconds since the current shell or script started executing. It starts counting from the moment the script begins running. | ||
| 11 | |||
| 12 | ```bash | ||
| 13 | #!/bin/bash | ||
| 14 | |||
| 15 | # Reset the timer to zero. | ||
| 16 | SECONDS=0 | ||
| 17 | |||
| 18 | # Do something. | ||
| 19 | sleep 5 | ||
| 20 | |||
| 21 | # Print the time elapsed. | ||
| 22 | echo "Time taken: $SECONDS seconds" | ||
| 23 | ``` | ||
