Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16470

Re: Undocumented feature: Unnamed fifo '<(:)'

From felix <felix@f-hauri.ch>
Newsgroups gnu.bash.bug
Subject Re: Undocumented feature: Unnamed fifo '<(:)'
Date 2020-06-28 18:35 +0200
Message-ID <mailman.563.1593362349.2574.bug-bash@gnu.org> (permalink)
References <20200628134945.GB24863@medium.hauri> <CANaoh6KSJS8X73Zqj7M8TT6_gAOjGraZx1EaEVwUNN_=Yya3wQ@mail.gmail.com> <20200628163559.GA3718@medium.hauri>

Show all headers | View raw


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 <felix@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  -  <felix@f-hauri.ch>  -  http://www.f-hauri.ch

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Undocumented feature: Unnamed fifo '<(:)' felix <felix@f-hauri.ch> - 2020-06-28 18:35 +0200

csiph-web