Awk detect stdin
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
Perl, Ruby and PHP can detect stdin:
$ perl -e 'print -t ? "no stdin" : "stdin"'
no stdin
$ echo | perl -e 'print -t ? "no stdin" : "stdin"'
stdin
$ ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
no stdin
$ echo | ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
stdin
$ php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
no stdin
$ echo | php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
stdin
Does Awk have some way to do this? I tried ARGC but its the same in both cases:
$ awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
$ echo | awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
awk terminal tty stdin
add a comment |Â
up vote
0
down vote
favorite
Perl, Ruby and PHP can detect stdin:
$ perl -e 'print -t ? "no stdin" : "stdin"'
no stdin
$ echo | perl -e 'print -t ? "no stdin" : "stdin"'
stdin
$ ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
no stdin
$ echo | ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
stdin
$ php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
no stdin
$ echo | php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
stdin
Does Awk have some way to do this? I tried ARGC but its the same in both cases:
$ awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
$ echo | awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
awk terminal tty stdin
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Perl, Ruby and PHP can detect stdin:
$ perl -e 'print -t ? "no stdin" : "stdin"'
no stdin
$ echo | perl -e 'print -t ? "no stdin" : "stdin"'
stdin
$ ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
no stdin
$ echo | ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
stdin
$ php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
no stdin
$ echo | php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
stdin
Does Awk have some way to do this? I tried ARGC but its the same in both cases:
$ awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
$ echo | awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
awk terminal tty stdin
Perl, Ruby and PHP can detect stdin:
$ perl -e 'print -t ? "no stdin" : "stdin"'
no stdin
$ echo | perl -e 'print -t ? "no stdin" : "stdin"'
stdin
$ ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
no stdin
$ echo | ruby -e 'puts $stdin.isatty ? "no stdin" : "stdin"'
stdin
$ php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
no stdin
$ echo | php -r 'print posix_isatty(STDIN) ? "no stdin" : "stdin";'
stdin
Does Awk have some way to do this? I tried ARGC but its the same in both cases:
$ awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
$ echo | awk 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
no stdin
awk terminal tty stdin
asked Mar 31 at 14:22
Steven Penny
2,28821635
2,28821635
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
Your perl, ruby and php examples test whether stdin exists. Your awk approach just tests whether stdin should be used.
You can use system("tty")
in awk to do that.
1
Nice - looks likesystem("[ -t 0 ]")
works too
â Steven Penny
Mar 31 at 14:52
add a comment |Â
up vote
1
down vote
ARGC
is the number of command-line arguments present. (indexed from1
)
In both mentioned cases the awk command/expression 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
is considered as the 1st argument independently of whether any data was piped to the current command.
To check for the file name of the terminal connected to standard input:
echo "a" | awk 'BEGIN "tty" '
stdin
awk 'BEGIN "tty" '
no stdin
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
Your perl, ruby and php examples test whether stdin exists. Your awk approach just tests whether stdin should be used.
You can use system("tty")
in awk to do that.
1
Nice - looks likesystem("[ -t 0 ]")
works too
â Steven Penny
Mar 31 at 14:52
add a comment |Â
up vote
3
down vote
accepted
Your perl, ruby and php examples test whether stdin exists. Your awk approach just tests whether stdin should be used.
You can use system("tty")
in awk to do that.
1
Nice - looks likesystem("[ -t 0 ]")
works too
â Steven Penny
Mar 31 at 14:52
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
Your perl, ruby and php examples test whether stdin exists. Your awk approach just tests whether stdin should be used.
You can use system("tty")
in awk to do that.
Your perl, ruby and php examples test whether stdin exists. Your awk approach just tests whether stdin should be used.
You can use system("tty")
in awk to do that.
answered Mar 31 at 14:48
Hauke Laging
53.2k1282130
53.2k1282130
1
Nice - looks likesystem("[ -t 0 ]")
works too
â Steven Penny
Mar 31 at 14:52
add a comment |Â
1
Nice - looks likesystem("[ -t 0 ]")
works too
â Steven Penny
Mar 31 at 14:52
1
1
Nice - looks like
system("[ -t 0 ]")
works tooâ Steven Penny
Mar 31 at 14:52
Nice - looks like
system("[ -t 0 ]")
works tooâ Steven Penny
Mar 31 at 14:52
add a comment |Â
up vote
1
down vote
ARGC
is the number of command-line arguments present. (indexed from1
)
In both mentioned cases the awk command/expression 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
is considered as the 1st argument independently of whether any data was piped to the current command.
To check for the file name of the terminal connected to standard input:
echo "a" | awk 'BEGIN "tty" '
stdin
awk 'BEGIN "tty" '
no stdin
add a comment |Â
up vote
1
down vote
ARGC
is the number of command-line arguments present. (indexed from1
)
In both mentioned cases the awk command/expression 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
is considered as the 1st argument independently of whether any data was piped to the current command.
To check for the file name of the terminal connected to standard input:
echo "a" | awk 'BEGIN "tty" '
stdin
awk 'BEGIN "tty" '
no stdin
add a comment |Â
up vote
1
down vote
up vote
1
down vote
ARGC
is the number of command-line arguments present. (indexed from1
)
In both mentioned cases the awk command/expression 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
is considered as the 1st argument independently of whether any data was piped to the current command.
To check for the file name of the terminal connected to standard input:
echo "a" | awk 'BEGIN "tty" '
stdin
awk 'BEGIN "tty" '
no stdin
ARGC
is the number of command-line arguments present. (indexed from1
)
In both mentioned cases the awk command/expression 'BEGIN print ARGC == 1 ? "no stdin" : "stdin"'
is considered as the 1st argument independently of whether any data was piped to the current command.
To check for the file name of the terminal connected to standard input:
echo "a" | awk 'BEGIN "tty" '
stdin
awk 'BEGIN "tty" '
no stdin
edited Mar 31 at 15:02
answered Mar 31 at 14:46
RomanPerekhrest
22.4k12144
22.4k12144
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f434678%2fawk-detect-stdin%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password