[sf-lug] SF-LUG meeting notes for Sunday June 2, 2019

Rick Moen rick at linuxmafia.com
Mon Jun 3 21:21:20 PDT 2019


Quoting Alex Kleider (akleider at sonic.net):

> I tried your script:

Short version:  It turns out I assumed GNU awk, but failed to say so.

> #!/bin/sh
> echo "Type the future date in ISO 8601 (YYYY-MM-DD) format."
> read futuredate
> echo $futuredate | tr -s '-' ' ' | awk '{dt=mktime($0 "
> 00-00-00")-systime(); print int(dt/86400+1) " days";}'
> 
> ... with the following result:
> 
> Type the future date in ISO 8601 (YYYY-MM-DD) format.
> 2019-07-01
> awk: line 2: function systime never defined
> awk: line 2: function mktime never defined
> 
> Your system appears to have 'features' that my (Ubuntu 18-04) lacks.

It may be that the implementation of awk found first via $PATH on your
system isn't the GNU implementation of awk (sometimes called 'gawk').
Am guessing that I relied on GNU awk's time functions
(https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html),
and that I completely failed to document the GNU-ism, in which case my
bad!  In fact, I'm going to go back and document that foible in a
comment line.  Thank you for calling attention to that oversight,
seriously, as I hate to give people frustrating and mysterious script
failures.

(Short pause, while Rick does some belated research.)

According to
https://askubuntu.com/questions/710379/do-i-need-to-install-awk-or-is-it-inbuilt-in-ubuntu,
as of Ubuntu 14.04, the default awk in Ubuntu was mawk, pulled in as a
dependency of the basic lsb-core package.  If you want to also have the
much more feature-rich GNU awk, you can get it by doing 'sudo apt-get
install gawk'.

'mawk' is short for 'Mike's awk', a small & fast awk interpreter written
in C by Mike Brennan, implementing (only) the POSIX standard definition
of awk, and not the gobs of extra stuff in GNU awk.  'mawk' is the
system default awk in both Ubuntu and Debian, so evidently at some point
in the past I also installed GNU awk, made it the default choice, and
forgot entirely.

linuxmafia:~# update-alternatives --list awk
/usr/bin/gawk
/usr/bin/mawk
linuxmafia:~#

I'm definitely _not_ going to go back and figure out how to implement
the systime and mktime functions in generic awk, because -- man! -- date
calculations are hair-pullingly complex to code, and I vaguely recall
heaving a gusty sigh of relief when I found GNU awk's time functions so
I didn't have to code that myself.

Again, thanks.




More information about the sf-lug mailing list