user3446120
user3446120

Reputation: 77

How to make shell execute something immediately after user input

I have a task where I need the shell to execute something immediately after user's input.

Example:

root@hq> pwd
<my user defined function>
/home/users/home40/spandiya
root@hq> 

I need my defined function to run immediately after user inputs "pwd", how do i do that? I do not want PROMPT_COMMAND which is executed by shell just before PS1.

I need my script to be executed immediately after user input.

Upvotes: 0

Views: 391

Answers (1)

anubhava
anubhava

Reputation: 786359

Here is a work-around using trap DEBUG:

mycmd() { tty; echo "custom command"; }

trap 'mycmd' DEBUG

$ pwd
/dev/cons0
custom command
/home/user

mycmd function runs just after user input but before executing user's entered command.

Upvotes: 1

Related Questions