Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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 at 13:14

1 Answer 1

up vote 10 down vote accepted

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

$ cat nohistory.sh
#!/bin/bash
set -o | grep history
history

.

$ ./nohistory.sh
history         off

.

$ cat history.sh
#!/bin/bash
set -o history
set -o | grep history
history

.

$ ./history.sh
history         on
    1  set -o | grep history
    2  history
share|improve this answer
1  
Thank your for your great answer :) –  Sepahrad Salour May 2 at 13:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.