using history command in the shell script

2019-08-18 23:22发布

问题:

I'm trying to get the command history inside a shell script. It doesn't work unless I take out the #!/bin/bash

Any clues on how I can get it to work, or to achieve the same effect without removing #!/bin/bash?

Anyone know why it works to remove #!/bin/bash?

回答1:

When you take out the shebang line it's being run by your current shell. Bash won't have any history to report unless you're using an "interactive" shell. Try changing your shebang line to:

#!/bin/bash -i

which will cause bash to start an interactive shell.



标签: linux shell