shell scripting : date Besonderheiten bei MacOS

bivvo

Mitglied
Thread Starter
Dabei seit
13.07.2021
Beiträge
24
Reaktionspunkte
3
Hallo zusammen,

ich hab ein recht komplexes Shell-Script, das primär auf Debian läuft - ich möchte es aber auch unter MacOS lauffähig haben.

Könnt ihr mir bitte helfen, die "date commands" für MacOS zu "übersetzen"?

Bash:
tmp_todayDay=$(date --utc +"%d");      # aktueller Tag
tmp_todayHour=$(date --utc +"%H");     # aktuelle Stunde
tmp_todayMinutes=$(date --utc +"%M" ); # aktuelle Minute

tmp_payTimestampDay=$(date --utc -d @"${settings[${NODE}_payTimestamp]}" +"%d");  # *_payTimestamp enthält einen UNIX-Timestamp
tmp_payDateHour=$(date --utc -d @"${settings[${NODE}_payTimestamp]}" +"%H" );     # *_payTimestamp enthält einen UNIX-Timestamp
tmp_payDateMinutes=$(date --utc -d @"${settings[${NODE}_payTimestamp]}" +"%M" );  # *_payTimestamp enthält einen UNIX-Timestamp

Ich recherchiere parallel selbst weiter. Danke für eure Unterstützung!
 
Bash:
date -ju +"%H" # wie bekomme ich die führende Null weg?
date -ju +"%M" # wie bekomme ich die führende Null weg?
date -ju +"%d"

tmp_payDateDay=$(date -juf "%s" $tmp_payTimestamp +"%d");
tmp_payDateHour=$(date -juf "%s" $tmp_payTimestamp +"%H");
tmp_payDateMinutes=$(date -juf "%s" $tmp_payTimestamp +"%M");

hat sich erledigt :)
 
Zuletzt bearbeitet:
%-H funktioniert nicht?

kann grad selbst nicht prüfen, habe nur iOS vor mir

Quelle:
https://man7.org/linux/man-pages/man1/date.1.html
Code:
 By default, date pads numeric fields with zeroes.  The following
       optional flags may follow '%':

       -      (hyphen) do not pad the field

       _      (underscore) pad with spaces

       0      (zero) pad with zeros

       +      pad with zeros, and put '+' before future years with >4
              digits

       ^      use upper case if possible

       #      use opposite case if possible

       After any flags comes an optional field width, as a decimal
       number; then an optional modifier, which is either E to use the
       locale's alternate representations if available, or O to use the
       locale's alternate numeric symbols if available
 
Beachte bitte das MacOS ein BSD und kein GNU ist.
Die BSD Tools haben teils andere Parameter.
Notfalls GNU Tools installieren.
 
  • Gefällt mir
Reaktionen: warnochfrei, dg2rbf, ruerueka und eine weitere Person
Zurück
Oben Unten