how to grep error messages

Soren Orel soren.orel at
Sun Jun 28 09:39:55 UTC 2009

I can /dev/null the error messages like:

cd "$1" 2> /dev/null

e.g.: I get error If "$1" has spaces in it

Ok, but how can I grep the error message? I tried:

if cd "$1" 2> grep -i "No such file or directory"; then echo "badbadbad";
exit; fi

But it doesn't work :S

thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the ubuntu-users mailing list