Bash Scripting - child process affecting parent process
So, I have a question about bash scripting. What I'm trying to do is write a simple script that I can use as an alias for "cd" which checks the directory that you're cd-ing to, and if it's not under your home directory, doesn't let you cd there.
I know there are better ways to do this (chroot, for instance, or rbash, although if I knew a way to have rbash but allow you to cd but just not outside your home tree that would be cool), but just bear with me.
Here's the script:
#echo "CUR: $cur"
#echo "NEW: $new"
true=`echo $new | grep $HOME`
#echo "TRUE: $true"
if [ -z $true ]; then
Seems to work fine when I call it as a script: for example if I run it (let's call it scd) as:
it outputs "RESTRICTED"
but it will accept
problem is that if you call it as a script like that, the child process doesn't reference/affect the parent process, so it won't seem as if you really are changing directory. And if I try using it as an alias with ". " so that the parent is affected by the child, it chokes on me:
-bash: /home/mthaddon: is a directory
Any help appreciated.