2

Is it possible to use Event Designators for history such as

   !!
   !n
   !-n
   !string

in bash scripts?

For example:

I have a variable, which keeps my input from command line in it. Also I have a tmp history. Every command which is executed inside my script is stored in this history and command

   history

work perfectly.

If I type

   !!

error occures: "!!: command not found".

1 Answers1

1

History expansion is turned on by default only for interactive shells. For the non-interactive shell that runs your script, you would have to turn it on explicitly at the beginning of your script with set -H.

chepner
  • 497,756
  • 71
  • 530
  • 681