Why does `ack` not output when used with` bash` as follows?

I assume this has nothing to do with ack, but more with bash:

Here we create file.txt, containing the string foobar, so we ackcan find in it foobar:

> echo foobar > file.txt
> echo 'ack foobar file.txt' > ack.sh
> bash ack.sh
foobar
> bash < ack.sh
foobar

So far so good. Buy, why doesn't he find anything in it?

> cat ack.sh | bash
(no output)

or

> echo 'ack foobar file.txt' | bash
(no output)

Why not ackfind foobarin the last two cases?

Adding unbuffer(from expect) in front makes it work, which I don't understand:

> echo 'unbuffer ack foobar file.txt' | bash
foobar

Even a stranger:

> cat ack2.sh
echo running
ack foobar file.txt
echo running again
unbuffer ack foobar file.txt

# Behaves as I'd expect
> bash ack2.sh
running
foobar
running again
foobar

# Strange output
> cat ack2.sh | bash
running
unbuffer ack foobar file.txt

Wassup with this outlet? These are echos unbuffer ack foobar file.txt, but not running again? A?

+6
source share
2 answers

ack , stdin - , . --nofilter, ack stdin tty.

:

# ack.sh
ack --nofilter foobar file.txt

:

$ cat ack.sh | bash
foobar

, . , , - ack, . , ack stdin, .


unbuffer "" ?

unbuffer, , stdin:

  Normally, unbuffer does not read from stdin.  This  simplifies  use  of
   unbuffer in some situations.  To use unbuffer in a pipeline, use the -p
   flag. ...

, ack ! stdin. , stdin , . , imo stdin, .

+4

, ack . . , . , ack , . ack script, ackrc . ack script, --noenv. , shell- ol grep.

, ?

+1

All Articles