I am a new Ubuntu/Linux user, I would like to ask a question as my title above.
For example, I have a bash file ./script
, I would like to make it run automatically when I type any command line. Once I execute command line pwd
then the ./script
will be executed. Once I type the next command line ls -la
then the ./script
will be executed again.
Best Answer
You need to set
PROMPT_COMMAND
variable. Fromman bash
:For example, this will write current date into
/tmp/PC
every time a command is executed: