Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: detect pipe
- X-seq: zsh-users 26423
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: detect pipe
- Date: Wed, 27 Jan 2021 20:57:36 -0800
- Archived-at: <https://zsh.org/users/26423>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-01/1b788ada-9c70-78e5-cc2c-1943000f2994%40eastlink.ca>
- In-reply-to: <CAH+w=7b=OmLb7+cbr0uFSgKay6yJksfbWyxD5WAVjXrrq3RAMw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <e7dc936d-4149-7882-5ac9-24e34b268985@eastlink.ca> <CAH+w=7b=OmLb7+cbr0uFSgKay6yJksfbWyxD5WAVjXrrq3RAMw@mail.gmail.com>
On 2021-01-27 3:59 p.m., Bart Schaefer wrote:
[[ -p /dev/fd/0 ]]
Nuts, using that it turns out that the issue is that my functions tend
to be called via aliases:
alias test2='noglob test1'
test1 ()
{
if [[ -p /dev/fd/0 ]]; then
echo "PIPES ARE AS BAD AS CIGARETTES"
grep --color=always "$1"
else
echo "NO, THEY AREN'T"
grep --color=always "$1" "$2"
fi
}
Testing it:
$ . test; echo "Now is the time for all good men" | test1 'the time'
PIPES ARE AS BAD AS CIGARETTES
Now is the time for all good men
$ . test; echo "Now is the time for all good men" | test2 'the time'
NO, THEY AREN'T
grep: : No such file or directory
$ . test; test1 'the time' junk # junk contains the same string
NO, THEY AREN'T
Now is the time for all good men
$ . test; test2 'the time' junk
NO, THEY AREN'T
Now is the time for all good men
... so the pipe test is fooled by the alias. Strange tho that it used to
work and still does *sometimes*. Very flaky. Dunno why an alias would
... well that's just it, I don't know.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author