简体   繁体   中英

using history command in the shell script

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM