I'm trying to return a boolean if a curl response has a status of 200.
curl https://www.example.com -I | grep ' 200 ' ? echo '1' : echo '0';
This however brings back:
grep: ?: No such file or directory
grep: echo: No such file or directory
grep: 1: No such file or directory
grep: :: No such file or directory
grep: echo: No such file or directory
grep: 0: No such file or directory
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
So I'm thinking (and from reading other threads) that grep doesn't support the ternary operator?
Is there a simple one liner to do this without creating a shell script? (also my grep ' 200 '
is loose but I figure I can make that more specific later)
curl ...... -I | grep ' 200 ' >/dev/null ; return "$?"
( in bash, $? (return of the last group of commands) gives the return of the last command executed in the pipe, grep here) . bash or grep don't have the ternary (aka "Elvis" ?: ) operator, but awk does, if you reaaaaally want to use it here. – Olivier Dulac Apr 19 '17 at 10:10