Why is the output on this ping outside the subshell?

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question
















  • 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














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?







share|improve this question
















  • 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












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?







share|improve this question












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?









share|improve this question











share|improve this question




share|improve this question










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 as if ping ... ; then echo "connected" ; else echo "not connected"; fi?
    – Nate Eldredge
    Nov 12 '17 at 1:28












  • 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







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










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





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    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






























    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





    share|improve this answer
























      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





      share|improve this answer






















        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





        share|improve this answer












        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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 '17 at 17:43









        Stephen Kitt

        143k22312377




        143k22312377



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?