[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Undocumented feature: Unnamed fifo '<(:)'
From: |
felix |
Subject: |
Re: Undocumented feature: Unnamed fifo '<(:)' |
Date: |
Wed, 1 Jul 2020 19:21:04 +0200 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
Thanks Pierre,
On Sun, Jun 28, 2020 at 10:48:42PM +0200, Pierre Gaston wrote:
> Maybe "coproc" is already the feature you need (limited to only 1 though)?
Correct: I missed this!
This work fine:
coproc stdbuf -o0 date -f - +%s 2>&1
DATEIN=${COPROC[1]} DATEOUT=$COPROC
echo >&$DATEIN 2009-02-13 23:31:30 UTC;read -u $DATEOUT out;declare -p out
declare -- out="1234567890"
echo foo bar >&$DATEIN ;read -u $DATEOUT out;declare -p out
declare -- out="date: invalid date 'foo bar'"
Unfortunely, coproc don't have option for separated error output...
If I want to handle errors, I could do this by using ``<(:)'' again:
exec 8<> <(:)
coproc stdbuf -o0 date -f - +%s 2>&8
DATEIN=${COPROC[1]} DATEOUT=$COPROC DATEERR=8
bound=wrong_date_$(uuidgen)
date_to_epoch() {
local _out
echo ${@:2}$'\n'$bound 1>&$DATEIN
read -u $DATEERR _out
if [ -z "${_out//*$bound*}" ]; then
read -u $DATEOUT $1
else
printf -v $1 %s "$_out"
read -u $DATEERR _out
return -1
fi
}
Usage: date_to_epoch <variable name> <unquoted date to convert>
Then
if date_to_epoch result 2009-02-13 23:31:30 UTC ;then
echo $result ; else echo ERROR: $result ;fi
1234567890
if date_to_epoch result bad entry ;then
echo $result ; else echo ERROR: $result ;fi
ERROR: date: invalid date 'bad entry'
Again, I use this for not only with `date` and `bc`, but with `mysql`, `ftp`
or even `ssh` too.
--
Félix Hauri - <felix@f-hauri.ch> - http://www.f-hauri.ch
- Re: Undocumented feature: Unnamed fifo '<(:)',
felix <=