Execute `ls` whenever user does a `cd` on terminal

0

I know bashrc is executed on terminal startup. But my use case is something like this,
To execute a specific command, say ls, whenever user executes another specific command, say cd, on the terminal.

My current solution is overriding cd command. But again that I feel is not a good solution. But my restriction here is that my user-group may not be aware of this new command that I may create and continue using cd.

swayamraina

Posted 2018-06-05T06:55:57.873

Reputation: 101

Question was closed 2018-06-05T21:58:07.233

Possible, but not a good idea to override commonly-used builtins. Rather create a new function like cdl. – slhck – 2018-06-05T07:12:17.147

Updated my question a bit. I already have overrided the cd command but I am hoping there may be a better solution. – swayamraina – 2018-06-05T07:22:17.390

Either the builtin is overridden and then cd can do something else, or it's not overriden and then cd is just a regular cd. Are you asking how to force other users to use your overridden cd? – Kamil Maciorowski – 2018-06-05T08:05:59.060

So, Yes I think I can take a flag which will decide this enhanced behaviour of cd – swayamraina – 2018-06-05T08:30:50.840

No answers