pepper
pepper

Reputation: 2197

print a message to the terminal when the user changes to a specific directory?

Is it possible, in unix, to make it so that a system message appears once a user has changed (cd) to a particular directory?

I know about motd, but I'm wondering if there is something similar to that for navigating in the shell. For instance, if I typed

cd /etc/apache2/

a message could be printed to the screen...something like:

"The latest configuration modified in this directory was..." "Please be careful modifying ... and ..."

something that all users could potentially see?

Upvotes: 3

Views: 892

Answers (1)

cmevoli
cmevoli

Reputation: 351

You could create a script file in each folder that you want to have execute when entering the folder. Then you can use the environment variable PROMPT_COMMAND to check for it and execute. For example:

export PROMPT_COMMAND='test -x ./.prompt_command && ./.prompt_command'

This will execute a script called .prompt_command in the current folder only if it exists and has its executable bit set.

Upvotes: 1

Related Questions