How to execute previous command in UNIX?

Hi,

I was able to use

!!

on the console.

But when I used

 !! 

in the run.sh, it says something like command not found.

Command line editing mode in a shell only works in interactive mode; not in a shell script. The characters used to rerun a command vary from shell to shell and within a shell from editing mode to editing mode.

I tend to prefer vi line editing mode and I usually use the Korn shell (vi line editing mode is also available in any other shell that conforms to the POSIX standards when you are not using a block mode terminal or terminal emulator). You obviously prefer a different line editing mode. (You can check the description of the shell set -o option built-in on the man page for your shell to see which, if any, line editing modes your shell provides.)

History substitution is not turned on on non-interactive shell for good reason.
If you must know:

set -o history
set -o histexpand

If you want to repeat the previous command, save it in a var.

Executing a previous command in a script is just copy-and-paste of that line in your editor. Or are you talking of a interactive input to the script that should be repeated? Then, as Aia said, save it, and extend your script by a small exclamation mark handler.