On Thu, Apr 07, 2022 at 11:42:42PM -0700, Bryan Turner wrote:
[...]
> > .git/hooks/pre-push: line 3: /dev/stdin: No such file or directory
> >
> > Is this a bug? How can I read stdin on a hook on windows?
>
> In Bitbucket Server's hooks (which had to work on Windows), we used &0.
>
> So you could do something like:
> while read line
> do
> # Something with line
> done < &0
>
> Hope this helps!
/dev/stdin is a Linux-specific thing, not mandated by POSIX, so you simply
cannot use it in portable POSIX shell scripts (by the way, the same applies
to the /proc/self/ hierarchy).
&0, which Bryan proposed, it s 100% correct thing as it's just a standard
way to refer to a file descriptor opened to the standard input stream (unless
reopened, but let's not digress).
I'd also hint to that `read` should read from FD 0 by default - there is
simply no need to explicitly redirect anything here.
I mean,
while read line; do ...; done < &0
is the same as unadorned
while read line; do ...; done
because FD 0 is what the standard input stream is opened to.