In order to prevent ressource eating, once `date -f - +%s` runned as background, date_to_epoch will become:
$ exec 8<> <(:) $ exec 9> >(exec stdbuf -o0 date -f - +%s >&8 2>&8) $ date_to_epoch() { echo >&9 ${@:2} read -t 1 -u 8 ${1:-answeredEpoch} } $ date_to_epoch _out 2009-02-13 23:31:30 UTC $ echo $_out 1234567890 U could test my demo script at https://f-hauri.ch/vrac/date1fork-demo.sh.txt or check for my `shell_connector' at https://f-hauri.ch/vrac/shell_connector.sh.txt This is not only interesting for `date`! I use them with `bc`, `tput`, and lot of other applications, upto `sqlite`, `mysql` and `postgresql` with ability of playing with temporary tables and other session related stuff... On Sun, Jun 28, 2020 at 10:55:59AM -0500, Dennis Williamson wrote: > date_to_epoch () { > date -d "$1" +%s > } > > _out=$(date_to_epoch "$_string") > On Sun, Jun 28, 2020, 8:50 AM felix <fe...@f-hauri.ch> wrote: > > ... > > _fifo=$(mktemp -u /tmp/fifo-XXXXXXXX) > > mkfifo $_fifo > > exec 9> >(exec stdbuf -o0 date -f - +%s >$_fifo 2>&1) > > exec 8<$_fifo > > rm $_fifo > > > > Then to convert human datetime to UNIX SECONDS: > > echo >&9 $_string > > read -t 1 -u 8 _out -- Félix Hauri - <fe...@f-hauri.ch> - http://www.f-hauri.ch