help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can Bash do simple math?


From: Koichi Murase
Subject: Re: Can Bash do simple math?
Date: Tue, 6 Aug 2024 07:50:26 +0900

2024年8月6日(火) 7:34 <bash@blaklinten.xyz>:
> I have a somewhat strange issue.
> In a script I use the `((VAR = expression ))` syntax to calculate a
> simple remainder by division:
>
>   ((DIFF = $2 - $1))
>   ((SECONDS = DIFF % 60))
> [...]

SECONDS is a Bash variable. It's automatically updated every second.
>From Bash Reference Manual:

https://www.gnu.org/software/bash/manual/bash.html#Bash-Variables
> SECONDS
>
> This variable expands to the number of seconds since the shell was
> started. Assignment to this variable resets the count to the value
> assigned, and the expanded value becomes the value assigned plus the
> number of seconds since the assignment. The number of seconds at shell
> invocation and the current time are always determined by querying the
> system clock. If SECONDS is unset, it loses its special properties,
> even if it is subsequently reset.

All-uppercase variable names are used/defined by the system. You
should usually avoid creating variables with all-uppercase names in
application scripts. You can use lowercase variable names.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]