I should change directory to "foo" when it comes available. How to do it? This far I've came up with:
cd `ls | grep foo`
But the problem with that is that if there is no match for grep, the directory is changed to home directory.
Another approach I had was using:
ls -1 | grep foo | xargs -r cd
In this example -r takes care of not running the command if there is no match. But it doesn't work since cd command is shell build-in and not an executable. Or something like that..
 Thanks for answers. If possible, could you also say how to combine mentioned functionality around grep somehow, so that I could use advanced regexp?