Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16513
| Path | csiph.com!goblin2!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail |
|---|---|
| From | felix <felix@f-hauri.ch> |
| 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 | <mailman.777.1593624078.2574.bug-bash@gnu.org> (permalink) |
| References | <20200628134945.GB24863@medium.hauri> <CAPSX3sTo8-kUffZ8NjkPXjiubshGYaP_Sw=nNro+tnEJ-kCD+A@mail.gmail.com> <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 | <CAPSX3sTo8-kUffZ8NjkPXjiubshGYaP_Sw=nNro+tnEJ-kCD+A@mail.gmail.com> |
| 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 <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <20200701172104.GE2143@medium.hauri> |
| X-Mailman-Original-References | <20200628134945.GB24863@medium.hauri> <CAPSX3sTo8-kUffZ8NjkPXjiubshGYaP_Sw=nNro+tnEJ-kCD+A@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:16513 |
Show key headers only | View raw
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
Back to gnu.bash.bug | Previous | Next | Find similar
Re: Undocumented feature: Unnamed fifo '<(:)' felix <felix@f-hauri.ch> - 2020-07-01 19:21 +0200
csiph-web