what is the differences between kill -PIPE $$ VS exit 1

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












in my bash script I used the following syntax in order to exit from bash script



kill -PIPE $$


I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script



so I use kill instead of exit 1



my question is



seems that



exit 1


and



kill -PIPE $$


are almost equal



dose my assumption is true ?



second - about kill -PIPE $$ ( any risks to use that syntax ? )










share|improve this question

















  • 1




    Related: unix.stackexchange.com/questions/48533/…
    – Kusalananda
    4 hours ago






  • 3




    Can you give an example of a script where exit 1 doesn't exit but kill -PIPE $$ does?
    – Joseph Sible
    4 hours ago










  • example - ( exit 1 ) or in sub shell
    – yael
    3 hours ago










  • But why would you use (exit 1) instead of exit 1?
    – xenoid
    1 hour ago














up vote
1
down vote

favorite












in my bash script I used the following syntax in order to exit from bash script



kill -PIPE $$


I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script



so I use kill instead of exit 1



my question is



seems that



exit 1


and



kill -PIPE $$


are almost equal



dose my assumption is true ?



second - about kill -PIPE $$ ( any risks to use that syntax ? )










share|improve this question

















  • 1




    Related: unix.stackexchange.com/questions/48533/…
    – Kusalananda
    4 hours ago






  • 3




    Can you give an example of a script where exit 1 doesn't exit but kill -PIPE $$ does?
    – Joseph Sible
    4 hours ago










  • example - ( exit 1 ) or in sub shell
    – yael
    3 hours ago










  • But why would you use (exit 1) instead of exit 1?
    – xenoid
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











in my bash script I used the following syntax in order to exit from bash script



kill -PIPE $$


I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script



so I use kill instead of exit 1



my question is



seems that



exit 1


and



kill -PIPE $$


are almost equal



dose my assumption is true ?



second - about kill -PIPE $$ ( any risks to use that syntax ? )










share|improve this question













in my bash script I used the following syntax in order to exit from bash script



kill -PIPE $$


I use it because sometimes in function or in internal shell in the script the exit 1 not realty exit from bash script



so I use kill instead of exit 1



my question is



seems that



exit 1


and



kill -PIPE $$


are almost equal



dose my assumption is true ?



second - about kill -PIPE $$ ( any risks to use that syntax ? )







linux bash kill exit






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 4 hours ago









yael

2,1091450




2,1091450







  • 1




    Related: unix.stackexchange.com/questions/48533/…
    – Kusalananda
    4 hours ago






  • 3




    Can you give an example of a script where exit 1 doesn't exit but kill -PIPE $$ does?
    – Joseph Sible
    4 hours ago










  • example - ( exit 1 ) or in sub shell
    – yael
    3 hours ago










  • But why would you use (exit 1) instead of exit 1?
    – xenoid
    1 hour ago












  • 1




    Related: unix.stackexchange.com/questions/48533/…
    – Kusalananda
    4 hours ago






  • 3




    Can you give an example of a script where exit 1 doesn't exit but kill -PIPE $$ does?
    – Joseph Sible
    4 hours ago










  • example - ( exit 1 ) or in sub shell
    – yael
    3 hours ago










  • But why would you use (exit 1) instead of exit 1?
    – xenoid
    1 hour ago







1




1




Related: unix.stackexchange.com/questions/48533/…
– Kusalananda
4 hours ago




Related: unix.stackexchange.com/questions/48533/…
– Kusalananda
4 hours ago




3




3




Can you give an example of a script where exit 1 doesn't exit but kill -PIPE $$ does?
– Joseph Sible
4 hours ago




Can you give an example of a script where exit 1 doesn't exit but kill -PIPE $$ does?
– Joseph Sible
4 hours ago












example - ( exit 1 ) or in sub shell
– yael
3 hours ago




example - ( exit 1 ) or in sub shell
– yael
3 hours ago












But why would you use (exit 1) instead of exit 1?
– xenoid
1 hour ago




But why would you use (exit 1) instead of exit 1?
– xenoid
1 hour ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote













exit 1 exits the current subshell environment with exit code 1, so for instance in:



sh -c '(echo 1; exit 1; echo 2); echo 3'


That exit 1 exits the subshell running the code in side (...) so that 2 is not output, and the parent shell process resumes echoing 3.



kill -s PIPE "$$" sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.



So in:



sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'


A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh). That parent process will die and not output 3 while the subshell process will carry on running in background and output 2.



If you ran that command in the bash or zsh shell (and a few other Bourne-like shells), those shells will set the $? parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).






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%2f478281%2fwhat-is-the-differences-between-kill-pipe-vs-exit-1%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
    3
    down vote













    exit 1 exits the current subshell environment with exit code 1, so for instance in:



    sh -c '(echo 1; exit 1; echo 2); echo 3'


    That exit 1 exits the subshell running the code in side (...) so that 2 is not output, and the parent shell process resumes echoing 3.



    kill -s PIPE "$$" sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.



    So in:



    sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'


    A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh). That parent process will die and not output 3 while the subshell process will carry on running in background and output 2.



    If you ran that command in the bash or zsh shell (and a few other Bourne-like shells), those shells will set the $? parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).






    share|improve this answer


























      up vote
      3
      down vote













      exit 1 exits the current subshell environment with exit code 1, so for instance in:



      sh -c '(echo 1; exit 1; echo 2); echo 3'


      That exit 1 exits the subshell running the code in side (...) so that 2 is not output, and the parent shell process resumes echoing 3.



      kill -s PIPE "$$" sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.



      So in:



      sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'


      A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh). That parent process will die and not output 3 while the subshell process will carry on running in background and output 2.



      If you ran that command in the bash or zsh shell (and a few other Bourne-like shells), those shells will set the $? parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).






      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote









        exit 1 exits the current subshell environment with exit code 1, so for instance in:



        sh -c '(echo 1; exit 1; echo 2); echo 3'


        That exit 1 exits the subshell running the code in side (...) so that 2 is not output, and the parent shell process resumes echoing 3.



        kill -s PIPE "$$" sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.



        So in:



        sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'


        A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh). That parent process will die and not output 3 while the subshell process will carry on running in background and output 2.



        If you ran that command in the bash or zsh shell (and a few other Bourne-like shells), those shells will set the $? parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).






        share|improve this answer














        exit 1 exits the current subshell environment with exit code 1, so for instance in:



        sh -c '(echo 1; exit 1; echo 2); echo 3'


        That exit 1 exits the subshell running the code in side (...) so that 2 is not output, and the parent shell process resumes echoing 3.



        kill -s PIPE "$$" sends the SIGPIPE signal to the process that executed the shell interpreter currently interpreting the script. The SIGPIPE by default causes processes to terminate, and the fact that that process has been killed by SIGPIPE is reflected in its exit status.



        So in:



        sh -c '(echo 1; kill -s PIPE "$$"; echo 2); echo 3'


        A SIGPIPE signal is sent by the subshell process to its parent process (the one that executed sh). That parent process will die and not output 3 while the subshell process will carry on running in background and output 2.



        If you ran that command in the bash or zsh shell (and a few other Bourne-like shells), those shells will set the $? parameter (its internal representation of the exit status of the last command) to something like 141, which is 128 + SIGPIPE (13 on most systems).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 34 mins ago









        ilkkachu

        53.1k780146




        53.1k780146










        answered 47 mins ago









        Stéphane Chazelas

        290k54541879




        290k54541879



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f478281%2fwhat-is-the-differences-between-kill-pipe-vs-exit-1%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            Installing NextGIS Connect into QGIS 3?

            One-line joke