In Shell script get the previous command executed

A

AJAY SHARMA

Guest
In a Shell Script i am executing few linux commands. i want a linux command to print the last executed command to the user

I came to know that ctrl p gives the last executed command, still i am not able to execute ctrl p in shell script.

Any one has some ideas on this or totally a different idea , then let me know.

Thank You in Advance.
 


What about this?:
Code:
echo "!!"
That should echo the last used command to the screen.
 
You could also use the HISTFILE bash variable to get the location of Bash history. Then use read and awk to read the last line of the file.
 


Top