The history command works in the terminal but is not written as a bash script

I have a simple single line that works fine in the terminal:

history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head

What he does: recently released the 10 most frequently used commands. (Do not ask me why I would like to achieve such a goal)

I start the editor and type the same from #!/bin/bashthe beginning:

#!/bin/bash
history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head

And I will say that I save it as script.sh. Then, when I go to the same terminal, enter bash script.shand press Enter, nothing will happen.

What I have tried so far: Googling. Many people have similar pains, but they are resolved by using sudo suor adding / removing spaces. None of this worked for me. Any idea where I could be wrong?


Edit:

. , script, .

, BryceAtNetwork23, history, ?

+4
3

. script. ~/.bashrc

popular_history() {
    history | sort -k2 | uniq -c --skip-fields=1 | sort -r -g | head
}
+4

, ; . script:

set -o history

- , , , , :

history -r ~/.bash_history

( bash , .bash_history.)

+3

bash, history .sh. . bash_history .sh.

, ,

#!/bin/bash
HISTFILE=~/.bash_history
set -o history 

: . .

0

All Articles