Why is the output on this ping outside the subshell?
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
I have a simple script that checks if an interface is connected:
connected=$(ping -I $1 -qc 1 8.8.8.8
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
I'm expecting that it should simply return "connected" or "not connected". When I actually use the script I always get back a warning before my output.
ping: Warning: source address might be selected on device other than enp0s25.
not connected
What is with the warning here, shouldn't it be part of the subshell?
bash ping subshell
add a comment |Â
up vote
6
down vote
favorite
I have a simple script that checks if an interface is connected:
connected=$(ping -I $1 -qc 1 8.8.8.8
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
I'm expecting that it should simply return "connected" or "not connected". When I actually use the script I always get back a warning before my output.
ping: Warning: source address might be selected on device other than enp0s25.
not connected
What is with the warning here, shouldn't it be part of the subshell?
bash ping subshell
4
Aside from redirecting standard error, wouldn't it be much simpler asif ping ... ; then echo "connected" ; else echo "not connected"; fi
?
â Nate Eldredge
Nov 12 '17 at 1:28
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
I have a simple script that checks if an interface is connected:
connected=$(ping -I $1 -qc 1 8.8.8.8
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
I'm expecting that it should simply return "connected" or "not connected". When I actually use the script I always get back a warning before my output.
ping: Warning: source address might be selected on device other than enp0s25.
not connected
What is with the warning here, shouldn't it be part of the subshell?
bash ping subshell
I have a simple script that checks if an interface is connected:
connected=$(ping -I $1 -qc 1 8.8.8.8
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
I'm expecting that it should simply return "connected" or "not connected". When I actually use the script I always get back a warning before my output.
ping: Warning: source address might be selected on device other than enp0s25.
not connected
What is with the warning here, shouldn't it be part of the subshell?
bash ping subshell
asked Nov 11 '17 at 17:34
Philip Kirkbride
2,2922470
2,2922470
4
Aside from redirecting standard error, wouldn't it be much simpler asif ping ... ; then echo "connected" ; else echo "not connected"; fi
?
â Nate Eldredge
Nov 12 '17 at 1:28
add a comment |Â
4
Aside from redirecting standard error, wouldn't it be much simpler asif ping ... ; then echo "connected" ; else echo "not connected"; fi
?
â Nate Eldredge
Nov 12 '17 at 1:28
4
4
Aside from redirecting standard error, wouldn't it be much simpler as
if ping ... ; then echo "connected" ; else echo "not connected"; fi
?â Nate Eldredge
Nov 12 '17 at 1:28
Aside from redirecting standard error, wouldn't it be much simpler as
if ping ... ; then echo "connected" ; else echo "not connected"; fi
?â Nate Eldredge
Nov 12 '17 at 1:28
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
18
down vote
accepted
The warning is sent to ping
âÂÂs standard error, which isnâÂÂt captured. If you want to ignore it, redirect it to /dev/null
explicitly:
connected=$(ping -I $1 -qc 1 8.8.8.8 2>/dev/null
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
18
down vote
accepted
The warning is sent to ping
âÂÂs standard error, which isnâÂÂt captured. If you want to ignore it, redirect it to /dev/null
explicitly:
connected=$(ping -I $1 -qc 1 8.8.8.8 2>/dev/null
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
add a comment |Â
up vote
18
down vote
accepted
The warning is sent to ping
âÂÂs standard error, which isnâÂÂt captured. If you want to ignore it, redirect it to /dev/null
explicitly:
connected=$(ping -I $1 -qc 1 8.8.8.8 2>/dev/null
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
add a comment |Â
up vote
18
down vote
accepted
up vote
18
down vote
accepted
The warning is sent to ping
âÂÂs standard error, which isnâÂÂt captured. If you want to ignore it, redirect it to /dev/null
explicitly:
connected=$(ping -I $1 -qc 1 8.8.8.8 2>/dev/null
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
The warning is sent to ping
âÂÂs standard error, which isnâÂÂt captured. If you want to ignore it, redirect it to /dev/null
explicitly:
connected=$(ping -I $1 -qc 1 8.8.8.8 2>/dev/null
&& echo "connected"
|| echo "not connected")
echo "$connected" | tail -n1
answered Nov 11 '17 at 17:43
Stephen Kitt
143k22312377
143k22312377
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%2f403930%2fwhy-is-the-output-on-this-ping-outside-the-subshell%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
4
Aside from redirecting standard error, wouldn't it be much simpler as
if ping ... ; then echo "connected" ; else echo "not connected"; fi
?â Nate Eldredge
Nov 12 '17 at 1:28