3

I have a question about interactive detection in bash.

The following script prints if it is called in interactive mode or not.

$ cat int.sh 
#!/bin/bash

if [ -t 0 ]; then
    echo "interactive"
else
    echo "not interactive"
fi

Some call examples...

$ ./int.sh 
interactive
$ echo toto | ./int.sh
not interactive
$ ./int.sh < ./int.sh
not interactive
$ ./int.sh <<EOF
> hello world!
> EOF
not interactive

But why the result is interactive for the following case ?

$ ./int.sh <( cat ./int.sh )
interactive
1
  • Note that what you're testing is whether the shell's standard input is a terminal. This is one meaning for “interactive” that makes sense, but it's not the meaning of “interactive” in shell terminology (which is whether the shell has enabled interactive features such as command line edition, as opposed to a shell instance that was started to execute a script). Feb 25, 2015 at 23:07

1 Answer 1

3

The <(...) statement in bash is process substitution. The process in <(...) is run with its input or output connected to a FIFO or some file in /dev/fd. See it with:

echo <(echo foo)

It prints something like /dev/fd/63. That is the file descritor. The <(...) part is then replaced with that file descriptor. So in your statement the call would be for example:

./int.sh <( cat ./int.sh )

Is replaced with:

./int.sh /dev/fd/63

So, it's just an argument to the script ./int.sh, that is still called interactively.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .