Created
March 8, 2013 23:56
-
-
Save guumaster/5121459 to your computer and use it in GitHub Desktop.
Deteccion de tipo de entrada/salida en ficheros bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [[ -t 1 ]]; then | |
echo "stdout is a terminal". | |
else | |
echo "stdout is NOT a terminal". | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment