I am writing a simple script to grep my bash history to find a particular string. On the command line, I can do the following, which works fine:
history | grep git
However, when I create a bash script with the same command as above, suddenly history
returns nothing:
#!/bin/bash
history | grep git
When I remove the first line #!/bin/bash
, my script works again. What is happening here? How can I use history
inside a bash script?