I have a two part question. First, is there a method to run a script whenever another (particular) script runs?
Secondly, I have created a script which I am using to 'override' the package 'cd' script, however, I've done this using aliases, and I'm wondering if there is a better (more proper) way to do this, or for that matter if my method will cause any errors done the road.
Allow me to explain my script... whenever "cd" is asked to move to a non-existent directory, it would than give the user the option to relocate the the 'deepest' existent directory in the entered path. It would be easier with an example...
Say I entered:
cd /var/www/html/foo
and that /var/www/html/foo does not exist, but /var/www/html does. the user would than be asked if they would like to proceed to /var/www/html.
I was able to make this happen using an alias and the following script:
#!/bin/bash
cd $*
<code to check if valid, et cetera>
However, this is done by using
alias cd='cdImproved'
As such, I'm uncertain if I will run into any problems doing this done the road, or if there is a more 'proper' way of doing the same thing.