How to add set -e to all default bashes?

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











up vote
0
down vote

favorite
1












To make a bash script exit after any failed command, you can add



set -e


Imagine, you have a CI agent which allow people to embed bash scripts as tasks in build jobs.



How to make the exit behaviour given by set -e default for all new bash instances? Is there some sort of bashrc hack for that?







share|improve this question


















  • 1




    Putting SHELLOPTS=errexit in the environment would do it, but in my opinion and that of many set -e is almost never the right way to do error handling.
    – Stéphane Chazelas
    Feb 1 at 19:56














up vote
0
down vote

favorite
1












To make a bash script exit after any failed command, you can add



set -e


Imagine, you have a CI agent which allow people to embed bash scripts as tasks in build jobs.



How to make the exit behaviour given by set -e default for all new bash instances? Is there some sort of bashrc hack for that?







share|improve this question


















  • 1




    Putting SHELLOPTS=errexit in the environment would do it, but in my opinion and that of many set -e is almost never the right way to do error handling.
    – Stéphane Chazelas
    Feb 1 at 19:56












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





To make a bash script exit after any failed command, you can add



set -e


Imagine, you have a CI agent which allow people to embed bash scripts as tasks in build jobs.



How to make the exit behaviour given by set -e default for all new bash instances? Is there some sort of bashrc hack for that?







share|improve this question














To make a bash script exit after any failed command, you can add



set -e


Imagine, you have a CI agent which allow people to embed bash scripts as tasks in build jobs.



How to make the exit behaviour given by set -e default for all new bash instances? Is there some sort of bashrc hack for that?









share|improve this question













share|improve this question




share|improve this question








edited Feb 1 at 19:42

























asked Feb 1 at 19:19









J. Doe

1033




1033







  • 1




    Putting SHELLOPTS=errexit in the environment would do it, but in my opinion and that of many set -e is almost never the right way to do error handling.
    – Stéphane Chazelas
    Feb 1 at 19:56












  • 1




    Putting SHELLOPTS=errexit in the environment would do it, but in my opinion and that of many set -e is almost never the right way to do error handling.
    – Stéphane Chazelas
    Feb 1 at 19:56







1




1




Putting SHELLOPTS=errexit in the environment would do it, but in my opinion and that of many set -e is almost never the right way to do error handling.
– Stéphane Chazelas
Feb 1 at 19:56




Putting SHELLOPTS=errexit in the environment would do it, but in my opinion and that of many set -e is almost never the right way to do error handling.
– Stéphane Chazelas
Feb 1 at 19:56










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You can make the present running bash shell activate the -e option with:



$ set -e


Just to confirm:



$ echo "$-"
himBHs
$ set -e
ehimBHs


As the bashrc file is sourced to interactive shells you can make all new bash shells use the -e option by adding this:



set -e


As one line at any place (that is executed) of the .bashrc script.



This is a very bad idea however, as there are many conditions under which the detection of a failed command fails and there are several cases where a failed command is desirable. Please read






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%2f421272%2fhow-to-add-set-e-to-all-default-bashes%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
    1
    down vote



    accepted










    You can make the present running bash shell activate the -e option with:



    $ set -e


    Just to confirm:



    $ echo "$-"
    himBHs
    $ set -e
    ehimBHs


    As the bashrc file is sourced to interactive shells you can make all new bash shells use the -e option by adding this:



    set -e


    As one line at any place (that is executed) of the .bashrc script.



    This is a very bad idea however, as there are many conditions under which the detection of a failed command fails and there are several cases where a failed command is desirable. Please read






    share|improve this answer
























      up vote
      1
      down vote



      accepted










      You can make the present running bash shell activate the -e option with:



      $ set -e


      Just to confirm:



      $ echo "$-"
      himBHs
      $ set -e
      ehimBHs


      As the bashrc file is sourced to interactive shells you can make all new bash shells use the -e option by adding this:



      set -e


      As one line at any place (that is executed) of the .bashrc script.



      This is a very bad idea however, as there are many conditions under which the detection of a failed command fails and there are several cases where a failed command is desirable. Please read






      share|improve this answer






















        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        You can make the present running bash shell activate the -e option with:



        $ set -e


        Just to confirm:



        $ echo "$-"
        himBHs
        $ set -e
        ehimBHs


        As the bashrc file is sourced to interactive shells you can make all new bash shells use the -e option by adding this:



        set -e


        As one line at any place (that is executed) of the .bashrc script.



        This is a very bad idea however, as there are many conditions under which the detection of a failed command fails and there are several cases where a failed command is desirable. Please read






        share|improve this answer












        You can make the present running bash shell activate the -e option with:



        $ set -e


        Just to confirm:



        $ echo "$-"
        himBHs
        $ set -e
        ehimBHs


        As the bashrc file is sourced to interactive shells you can make all new bash shells use the -e option by adding this:



        set -e


        As one line at any place (that is executed) of the .bashrc script.



        This is a very bad idea however, as there are many conditions under which the detection of a failed command fails and there are several cases where a failed command is desirable. Please read







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 1 at 19:25









        Isaac

        6,6371734




        6,6371734






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f421272%2fhow-to-add-set-e-to-all-default-bashes%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)