I have standalone PROMPT_COMMAND=
in my .bash_profile
. Every time user input a command, it's being run.
I want to get the first word of the last command by user.
For example, if the user runs: $ printf "Hey!"
, I want to access printf
from my PROMPT_COMMAND
.
$0
gives me -bash
and $1
, $2
, ... gives me arguments as said on the site below.
https://wiki.bash-hackers.org/scripting/posparams#the_first_argument
But how can I access the first word like printf
in the above example?
Preferably, I want to use the build-in commands as much and cleanly as possible.