Why does the history command do nothing in a script file?bash -c history produces no outputPermanently...

What is the "ls" directory in my home directory?

Dates on degrees don’t make sense – will people care?

Is there any proof that high saturation and contrast makes a picture more appealing in social media?

Prisoner on alien planet escapes by making up a story about ghost companions and wins the war

"Correct me if I'm wrong"

Why don't we have a weaning party like Avraham did?

What is the oldest commercial MS-DOS program that can run on modern versions of Windows without third-party software?

What does it cost to buy a tavern?

Drawing a second weapon as part of an attack?

Non-misogynistic way to say “asshole”?

Are there any individual aliens that have gained superpowers in the Marvel universe?

What was the first third-party commercial application for MS-DOS?

Very tricky nonogram - where to go next?

Has a life raft ever been successfully deployed on a modern commercial flight?

Should I include an appendix for inessential, yet related worldbuilding to my story?

Why don't countries like Japan just print more money?

Why isn't my calculation that we should be able to see the sun well beyond the observable universe valid?

What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?

Did the CIA blow up a Siberian pipeline in 1982?

Subtract the Folded Matrix

What are the current battlegrounds for people’s “rights” in the UK?

Is the specular reflection on a polished gold sphere white or gold in colour?

How to work with PETG? Settings, caveats, etc

How did the Vostok ejection seat safely eject an astronaut from a sealed space capsule?



Why does the history command do nothing in a script file?


bash -c history produces no outputPermanently Storing a command in bash historyWhy does bash output data instead of executing, when a script is piped?mkvmerge in a bash script does not executeWhy can I change bash history?Using only in-memory command historyHow do I open a terminal window and execute a command after the shell has opened?bash history where command runHistory with bash fileBash interactive - entire script writing to historyexecute command with sudo and execute Bash script with sudo






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







4















If I create a file containing



 #!/bin/bash 
history


and run it, I get no output. Running it manually in a terminal or sourceing the script file does produce output.



Why does history not work from a file?










share|improve this question

























  • For better understanding I changed the question..

    – Sepahrad Salour
    May 2 '14 at 13:14


















4















If I create a file containing



 #!/bin/bash 
history


and run it, I get no output. Running it manually in a terminal or sourceing the script file does produce output.



Why does history not work from a file?










share|improve this question

























  • For better understanding I changed the question..

    – Sepahrad Salour
    May 2 '14 at 13:14














4












4








4


3






If I create a file containing



 #!/bin/bash 
history


and run it, I get no output. Running it manually in a terminal or sourceing the script file does produce output.



Why does history not work from a file?










share|improve this question
















If I create a file containing



 #!/bin/bash 
history


and run it, I get no output. Running it manually in a terminal or sourceing the script file does produce output.



Why does history not work from a file?







bash shell-script command-history






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 2 '14 at 23:24









Gilles

559k13411471657




559k13411471657










asked May 2 '14 at 12:42









Sepahrad SalourSepahrad Salour

1,97131424




1,97131424













  • For better understanding I changed the question..

    – Sepahrad Salour
    May 2 '14 at 13:14



















  • For better understanding I changed the question..

    – Sepahrad Salour
    May 2 '14 at 13:14

















For better understanding I changed the question..

– Sepahrad Salour
May 2 '14 at 13:14





For better understanding I changed the question..

– Sepahrad Salour
May 2 '14 at 13:14










1 Answer
1






active

oldest

votes


















13














The second command does "work", but the history is not enabled for non-interactive shells which is why it returns nothing in your script.



Testing the default in a non-interactive shell:



nohistory.sh:



#!/bin/bash
set -o | grep history
history


Result:



$ ./nohistory.sh
history off


Enabling history with set -o history:



history.sh:



#!/bin/bash
set -o history
set -o | grep history
history


Result:



$ ./history.sh
history on
1 set -o | grep history
2 history





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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    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%2f127551%2fwhy-does-the-history-command-do-nothing-in-a-script-file%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    13














    The second command does "work", but the history is not enabled for non-interactive shells which is why it returns nothing in your script.



    Testing the default in a non-interactive shell:



    nohistory.sh:



    #!/bin/bash
    set -o | grep history
    history


    Result:



    $ ./nohistory.sh
    history off


    Enabling history with set -o history:



    history.sh:



    #!/bin/bash
    set -o history
    set -o | grep history
    history


    Result:



    $ ./history.sh
    history on
    1 set -o | grep history
    2 history





    share|improve this answer






























      13














      The second command does "work", but the history is not enabled for non-interactive shells which is why it returns nothing in your script.



      Testing the default in a non-interactive shell:



      nohistory.sh:



      #!/bin/bash
      set -o | grep history
      history


      Result:



      $ ./nohistory.sh
      history off


      Enabling history with set -o history:



      history.sh:



      #!/bin/bash
      set -o history
      set -o | grep history
      history


      Result:



      $ ./history.sh
      history on
      1 set -o | grep history
      2 history





      share|improve this answer




























        13












        13








        13







        The second command does "work", but the history is not enabled for non-interactive shells which is why it returns nothing in your script.



        Testing the default in a non-interactive shell:



        nohistory.sh:



        #!/bin/bash
        set -o | grep history
        history


        Result:



        $ ./nohistory.sh
        history off


        Enabling history with set -o history:



        history.sh:



        #!/bin/bash
        set -o history
        set -o | grep history
        history


        Result:



        $ ./history.sh
        history on
        1 set -o | grep history
        2 history





        share|improve this answer















        The second command does "work", but the history is not enabled for non-interactive shells which is why it returns nothing in your script.



        Testing the default in a non-interactive shell:



        nohistory.sh:



        #!/bin/bash
        set -o | grep history
        history


        Result:



        $ ./nohistory.sh
        history off


        Enabling history with set -o history:



        history.sh:



        #!/bin/bash
        set -o history
        set -o | grep history
        history


        Result:



        $ ./history.sh
        history on
        1 set -o | grep history
        2 history






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 hour ago









        muru

        39.6k595171




        39.6k595171










        answered May 2 '14 at 13:01









        Adrian FrühwirthAdrian Frühwirth

        1,6291114




        1,6291114






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f127551%2fwhy-does-the-history-command-do-nothing-in-a-script-file%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...