using history command in the shell script

2019-08-18 22:50发布

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?

标签: linux shell
1条回答
Melony?
2楼-- · 2019-08-18 23:07

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.

查看更多
登录 后发表回答