diff options
Diffstat (limited to 'content/notes')
| -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 | ``` | ||
