Figuring out if the input to a script is coming from the terminal or from a pipe is not something that I have ever had to use but I found the possibility very interesting so sharing it over here:
#!/bin/bash stdin="$(ls -l /dev/fd/0)" stdin="${stdin/*-> /}" ftype="$(stat --printf=%F $stdin)" if [[ "$ftype" == 'character special file' ]]; then echo Terminal elif [[ "$ftype" == 'regular file' ]]; then echo Pipe: $stdin else echo Unknown: $stdin fi
– Suramya
Source: Linux Journal