Run script each time cd is used
Hi,
Is there a way to automatically run a script each time i use the cd command? Thanks C19 |
Not directly, but you could create your own cd command which executes your script and then does the original cd. You can achieve the same with a bash alias.
|
Hi,
So if I creat an alias in my .profile could i call the script from there? how would I do that? |
Try something like this, substitution the echo for your own command:
Code:
pu@slackw:~$ alias |
Hey uselpa,
Thanks for that I managed to sort it out. I have another question, I would like to create an alias that when i cd it automatically runs ls? Thanks C19 |
Then it's easier to use functions:
Code:
pu@slackw:~$ function cd() { builtin cd "$*" ; ls ; } |
Thanks
but i've pasted your code in my .profile run it again with . .profile and i get this error? ksh: syntax error: `(' unexpected |
Which shell are you using? bash or ksh? Which distro are you using?
My example is based on bash, which is the standard shell on Linux. |
Hi,
I'm using ksh and i'm using a flavour of unix svr4 Cheers C19 |
I haven't used ksh so I can't help you there. But be aware that in the Linux world people will assume that you use bash because that's the default shell for Linux (at least for all the distros I've installed in the past). So when you post a shell question to this (mainly Linux) forum, please specify that you use Korn Shell.
|
Hi,
I thought ksh meant Korn Shell? |
Yes, ksh is Korn Shell. But you didn't say that you used ksh, that's my point.
|
Quote:
|
I wasn't being rude. Just pointing out that if you ask questions related to shell in a Linux forum, you need to specify that you use ksh right from the start.
|
Cool, no probs
Cheers |
All times are GMT -5. The time now is 09:39 PM. |