How can I get the last executed command from bash? I know that !!:p prints the last command, but it seems I can't use that anywhere except the bash prompt. I tried
echo !!:p but it prints
~/Downloads$ pwd Downloads ~/Downloads$ echo !!:p echo pwd
I want to use this inside the
PROMPT_COMMAND variable so I need to get it as a string so I can just print it out. Is there an easy way to do this? Am I looking in the wrong place?
I guess I'm not clear. I need to store the last command run so I can re-display it after the output and before the next prompt. For example this is what I want the output to look like:
~/Downloads$ pwd Downloads pwd ~/Downloads$
I'm doing this my changing my prompt in my
PROMPT_COMMAND='echo -en "\033[38;5;2m"!!:p"\033[0m\n"' PS1='\W\$'
But !!:p only works correctly from the bash prompt. So how can I store the last command so that I can reprint it later?