[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to grep error messages



$ sh script.sh /home/user/Desktop/some existing dir with spaces
script.sh: line 2: cd: /home/gbor/Desktop/some: No such file or directory
script.sh: line 2: [: -ne: unary operator expected

$ cat script.sh
#!/bin/bash
if [ $(cd "$1") -ne 0 ]
then echo "badbadbad" ; exit 1
fi


I just want to make my script:
http://groups.google.com/group/ubuntu-users-archive/browse_thread/thread/117d54b69cd92a71/e8e03d8824b9323e?show_docid=e8e03d8824b9323e&pli=1#

more "user secure" :D:S

thats why I'm searching for a method to warn the user, if it had started my script with a bad path, e.g.: doesn't wrote escape char before space, or put quote around the path, like: "/home/user/Desktop/some existing dir with spaces"

thanks :P:)

On Sun, Jun 28, 2009 at 11:39 AM, Soren Orel <soren.orel@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!


Reply to: