Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Chet Ramey Newsgroups: gnu.bash.bug Subject: Re: read -t 0 fails to detect input. Date: Thu, 19 Dec 2019 11:40:00 -0500 Lines: 37 Approved: bug-bash@gnu.org Message-ID: References: <7e6fccb4-e5b5-eb2b-8b12-eeee9d638ae1@case.edu> Reply-To: chet.ramey@case.edu NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1576773609 1425 209.51.188.17 (19 Dec 2019 16:40:09 GMT) X-Complaints-To: action@cs.stanford.edu Cc: chet.ramey@case.edu To: Bize Ma , bug-bash Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1576773602; bh=+oaRyCNamzyFhrRe1fotZk9TBBnDEi8T7fhtRas9EHw=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=hvRiPUOSKRGZshJ/5wxoV73SSvrS4EoiHPzpftONNHdcJgZ6zUoYiYRASV3htSKxie rMk11s4vyrvpCVQ+S3xyNAQ72mL5lT3aHVly/COU7uirSHA5UVidbfU3HevCyy9U3q8 VN6GxQTlzpCDRI/TbonuRJYMCgiGTgOoo7EOdxlxXvzkZd1g3nrFcNJpKuJox0Tly6e lVf/f3MnsQkJso+SwDG9+cCexDaow61EmUMtCqjQGZ7usadyWjiR5cIEsNSeep3O3X/ H+VTBNuDHHPZzeljBM4iY25YB3d4bI+uFiIVJ5y5uxRUEEhhD3s8m+O3C4EV8un7SjK Mhy1vj7g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1576773601; bh=Za4tdopfkU/11NNBfuFbQSxT3UL9wlS0lJjmk7DMS24=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=1hYf0Vtc+fPKj2dhyd5plZNvp2rRgM4ppPIAsH8DV0s3RSLs5QpuLYN+NjzhlKQWxF oG8oOg4tcIZ6BHXXkmJw/DELiN/w0mkMpDfwx9uoJswQBSTolurXo0G/yacYdPT5ltd 5WihgOYuRpMRSZr/7vYxleYMbtAhJQnNsezzkqEHt1thB7UI//WCCka9mV01Ef3LDX7 R0Tt3vlqlv6aTinqu2Ed+rHbcPgx1INtCfREwS3EhTI+EKVfyknG14oqHIk6MwfeC9j lQLq+zBozKeDpG/+MULHsqVd+9UvMpSoc9it+QJ9pFq8ywzsnkW/O81YTY2FVqLL2h0 MfW8Fm4Q== User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 In-Reply-To: Content-Language: en-US X-Junkmail-Status: score=7/90, host=mpv3-2015.case.edu X-Junkmail-PrAS-Raw: score=7/90, refid=2.7.2:2019.12.19.154817:17:7.944, ip=, rules=DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __SUBJ_REPLY, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __TO_MALFORMED_2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC1, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __URI_WITH_PATH, __URI_NO_WWW, __CP_URI_IN_BODY, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __URI_IN_BODY, __URI_NOT_IMG, __MAIL_CHAIN, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODY_SIZE_1100_1199, BODYTEXTP_SIZE_3000_LESS, __MIME_TEXT_P1, __MIME_TEXT_ONLY, __URI_NS, HTML_00_01, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] X-Received-From: 129.22.103.194 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: <7e6fccb4-e5b5-eb2b-8b12-eeee9d638ae1@case.edu> X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:15756 On 12/18/19 6:40 PM, Bize Ma wrote: > It seems that read -t 0 should detect if there is input from a pipe (and > others). > > From man bash: > >>> If timeout is 0, read returns immediately, without trying to read any > data. >>> The exit status is 0 if input is available on the specified file > descriptor, non-zero otherwise. Bash-5.0 uses select/FIONREAD to determine whether or not there is input available on the file descriptor. Those don't wait; they test whether or not there is input on the specified file descriptor at the point they are called. > > So, it seems that this should print 1: > > $ true | read -t 0 var; echo $? > 1 > > And this should print 0 (input available), but it doesn't (most of the > time). > > $ echo value | read -t 0 var ; echo $? > 1 This is inherently racy: there is no guarantee that the echo will have written anything to the pipe by the time the read runs to test it. It depends on how the system schedules the processes. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/