|
|
|
|
|
by tytso
4675 days ago
|
|
Why not put something like this in your .bashrc or your .profile file instead? function bd () { OLDPWD=`pwd`
NEWPWD=`echo $OLDPWD | sed 's|\(.*/'$1'[^/]*/\).*|\1|'`
index=`echo $NEWPWD | awk '{ print index($1,"/'$1'"); }'`
if [ $index -eq 0 ] ; then
echo "No such occurrence."
else
echo $NEWPWD
cd "$NEWPWD"
fi
}That way you don't have to execute a separate shell script and source its output. Also note that the "export OLDPWD" wasn't necessary in your script, either. Why pollute the environment of future processes spawned by your shell? |
|
Removed the 'export'. I wrote out of habit. Thanks a lot for pointing that out.