guumaster
3/8/2013 - 11:56 PM

Deteccion de tipo de entrada/salida en ficheros bash

Deteccion de tipo de entrada/salida en ficheros bash

#!/bin/bash
if [[ -t 1 ]]; then
    echo "stdout is a terminal".
else
    echo "stdout is NOT  a terminal".
fi

#!/bin/bash
if [[ -p /dev/stdin ]]
then
    echo "stdin is coming from a pipe"
fi
if [[ -t 0 ]]
then
    echo "stdin is coming from the terminal"
fi
if [[ ! -t 0 && ! -p /dev/stdin ]]
then
    echo "stdin is redirected"
fi
read
echo $REPLY