Comment

Comment by tytso

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?

parent tytso 13 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton