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;
}
If I create a file containing
#!/bin/bash
history
and run it, I get no output. Running it manually in a terminal or source
ing the script file does produce output.
Why does history
not work from a file?
bash shell-script command-history
add a comment |
If I create a file containing
#!/bin/bash
history
and run it, I get no output. Running it manually in a terminal or source
ing the script file does produce output.
Why does history
not work from a file?
bash shell-script command-history
For better understanding I changed the question..
– Sepahrad Salour
May 2 '14 at 13:14
add a comment |
If I create a file containing
#!/bin/bash
history
and run it, I get no output. Running it manually in a terminal or source
ing the script file does produce output.
Why does history
not work from a file?
bash shell-script command-history
If I create a file containing
#!/bin/bash
history
and run it, I get no output. Running it manually in a terminal or source
ing the script file does produce output.
Why does history
not work from a file?
bash shell-script command-history
bash shell-script command-history
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
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
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
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
add a comment |
add a comment |
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.
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
Required, but never shown
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
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
Required, but never shown
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
Required, but never shown
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
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
For better understanding I changed the question..
– Sepahrad Salour
May 2 '14 at 13:14