MVTC
MVTC

Reputation: 845

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?

Upvotes: 0

Views: 2464

Answers (1)

FatalError
FatalError

Reputation: 54551

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.

Upvotes: 6

Related Questions