Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: detect pipe
- X-seq: zsh-users 26422
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Ray Andrews <rayandrews@xxxxxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: detect pipe
- Date: Wed, 27 Jan 2021 15:59:20 -0800
- Archived-at: <https://zsh.org/users/26422>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/CAH%2Bw%3D7b%3DOmLb7%2Bcbr0uFSgKay6yJksfbWyxD5WAVjXrrq3RAMw%40mail.gmail.com>
- In-reply-to: <e7dc936d-4149-7882-5ac9-24e34b268985@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <e7dc936d-4149-7882-5ac9-24e34b268985@eastlink.ca>
On Wed, Jan 27, 2021 at 8:45 AM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> I have a function that as used this test for piping quite reliably:
>
> if [ ! -t 0 ]; then
>
> ... but today it stopped working.
[ -t 0 ] or [[ -t 0 ]] mean that the standard input is a terminal.
It's quite possible for standard input to be neither a terminal (so [[
! -t 0 ]] is true) nor a pipe. For example, redirection from a file
or use of a here-document will both take the then-branch of "if [[ !
-t 0 ]]; then ... else ... fi".
> there a better way? This is probably not strictly a zsh problem but the
> randomness of it working intermittently suggests some time lag or delay
A race condition would be unlikely to be a cause here.
[[ -p /dev/fd/0 ]] would be a more reliable test, because of the way
conditional expressions special case the prefix "/dev/fd/".
Messages sorted by:
Reverse Date,
Date,
Thread,
Author