If I create a file containing
and run it, I get no output. Running it manually in a terminal or
sourceing the script file does produce output.
history not work from a file?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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:
#!/bin/bash set -o | grep history history
$ ./nohistory.sh history off
Enabling history with
set -o history:
#!/bin/bash set -o history set -o | grep history history
$ ./history.sh history on 1 set -o | grep history 2 history