Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: felix Newsgroups: gnu.bash.bug Subject: Re: Undocumented feature: Unnamed fifo '<(:)' Date: Wed, 1 Jul 2020 19:21:04 +0200 Lines: 54 Approved: bug-bash@gnu.org Message-ID: References: <20200628134945.GB24863@medium.hauri> <20200701172104.GE2143@medium.hauri> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: usenet.stanford.edu 1593624079 10003 209.51.188.17 (1 Jul 2020 17:21:19 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Received-SPF: none client-ip=212.74.161.16; envelope-from=felix@f-hauri.ch; helo=smtp.f-hauri.ch X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/01 13:21:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, KHOP_HELO_FCRDNS=1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20200701172104.GE2143@medium.hauri> X-Mailman-Original-References: <20200628134945.GB24863@medium.hauri> Xref: csiph.com gnu.bash.bug:16513 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 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 - - http://www.f-hauri.ch