0

I have the following script (based on this):

#!/bin/bash

runtime=$(zenity --title "Send notification repeatedly" --entry "Enter the period in minutes like this: nn minutes")

endtime=$(date -ud "$runtime" +%s)

while [[ $(date -u +%s) -le $endtime ]]
do
    notify-send "Hello"
    sleep 10s
done

man date has this:

   -d, --date=STRING
          display time described by STRING, not 'now'

but I couldn't find an explanation for "STRING".

All of the following work when entered in the zenity window:

  • 1 minute
  • 1 minutes and
  • 1 min

But 1 m doesn't. Where is what is acceptable as "STRING" described? I couldn't find anything in man date.

The other thing is the purpose of +%s. What does it do?

2

3 Answers 3

2

You find it a bit below in man date:

DATE STRING

The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday".
A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.

To get to know what exactly is allowed and what not, you can read the info documentation.

So, run info date and switch to "Date input formats".


Regarding +%s see the Synopsis:

date [OPTION]... [+FORMAT]

with FORMAT being a long number of possible sequences, so here just the one you need:

%s     seconds since 1970-01-01 00:00:00 UTC

The + is just part of the syntax.


Additionally, some good reading: How can I get help on terminal commands?

1
1

All is said inside the manpage :

DATE STRING

The --date=STRING is a mostly free format human readable date string such as "Sun, 29 Feb 2004 16:21:42 -0800" or "2004-02-29 16:21:42" or even "next Thursday". A date string may contain items indicating calendar date, time of day, time zone, day of week, relative time, relative date, and numbers. An empty string indicates the beginning of the day. The date string format is more complex than is easily documented here but is fully described in the info documentation.

Here is examples given :

EXAMPLES

Convert seconds since the epoch (1970-01-01 UTC) to a date

$ date --date='@2147483647'

Show the time on the west coast of the US (use tzselect(1) to find TZ)

$ TZ='America/Los_Angeles' date

Show the local time for 9AM next Friday on the west coast of the US

$ date --date='TZ="America/Los_Angeles" 09:00 next Fri'

You could also find that man page on internet

1

From info '(coreutils) date invocation':

The program accepts the following options. Also see *note Common options::.

‘-d DATESTR’ ‘--date=DATESTR’ Display the date and time specified in DATESTR instead of the current date and time. DATESTR can be in almost any common format. It can contain month names, time zones, ‘am’ and ‘pm’, ‘yesterday’, etc. For example, ‘--date="2004-02-27 14:19:13.489392193 +0530"’ specifies the instant of time that is 489,392,193 nanoseconds after February 27, 2004 at 2:19:13 PM in a time zone that is 5 hours and 30 minutes east of UTC. Note: input currently must be in locale independent format. E.g., the LC_TIME=C below is needed to print back the correct date in many locales: date -d "$(LC_TIME=C date)"

The +:

If given an argument that starts with a ‘+’, ‘date’ prints the current date and time (or the date and time specified by the ‘--date’ option, see below) in the format defined by that argument, which is similar to that of the ‘strftime’ function. Except for conversion specifiers, which start with ‘%’, characters in the format string are printed unchanged. The conversion specifiers are described below.

The %s:

‘date’ conversion specifiers related to times. ...

‘%s’ seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC. Leap seconds are not counted unless leap second support is available. *Note %s-examples::, for examples. This is a GNU extension.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .