Skip to content

Instantly share code, notes, and snippets.

@proger
Created July 26, 2012 07:59
Show Gist options
  • Save proger/3180858 to your computer and use it in GitHub Desktop.
Save proger/3180858 to your computer and use it in GitHub Desktop.
kinda portable way to do isatty() in a shell
% cat t.sh ~
#!/bin/sh
test -c /dev/stdin && echo "char"
test -p /dev/stdin && echo "named pipe"
test -S /dev/stdin && echo "socket"
test ! -f /dev/stdin && echo "not regular"
test -f /dev/stdin && echo "regular"
% sh ./t.sh ~
char
not regular
% echo hi | sh ./t.sh ~
named pipe
not regular
% sh ./t.sh < /etc/passwd ~
regular
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment