how to grep error messages
cwillu
cwillu at cwillu.com
Wed Jul 1 18:55:11 UTC 2009
option one: "use the error codes"
cd "$1" || echo something went wrong!
cd "$1" && echo everything went right!
option two: "you were so close!"
cd "$1" 2>&1 | grep -i "No such file or directory"
The extra '&1' is needed to send cd's (actually bash's, as cd is a
builtin) error output to grep's standard input
On Sun, Jun 28, 2009 at 3:39 AM, Soren Orel<soren.orel at gmail.com> wrote:
> 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!
>
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
>
>
More information about the ubuntu-users
mailing list