我正在使用git-bash
:
GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)
我声明了以下简单函数:
f() { local f=${1:-/dev/stdin}; sed 's/a/b/g' "$f"; }
当我使用管道或文件向该函数提供输入时,一切正常:
$ cat file
a
b
c
$ f file
b
b
c
$ printf 'a\nb\n' | f
b
b
但是当我使用here-doc或here-string时,/dev/stdin
似乎不存在:
$ f << eof
> a
> b
> eof
sed: can't read /dev/stdin: No such file or directory
尽管将cat
与here-doc一起使用似乎可以正常工作:
$ cat << eof
> a
> b
> eof
a
b
此代码在我的Linux发行版中工作正常。如何更改它,使其与stdin
或什至在git-bash
中的文件一起工作?