This question already has an answer here:
I have the following Bash script
case $- in (*H*) echo enabled ;; (*) echo disabled ;; esac set -H case $- in (*H*) echo enabled ;; (*) echo disabled ;; esac pwd last_command="!!" echo $last_command
disabled enabled /home/user !!
The first line of code checks to see if history expansion is enabled. The second enables history expansion. The third is the same as the first. Then its runs
pwd and finally assigns what should be last command to
last_command and prints this variable.
The history is not expanding. What is going on?