/dev/null changes result, why? ( How to know if svn repository exists )

Hi,

Because I am writing last few weeks some scripts for a project, I do want to put those under svn ( subversion ). As a scripting exercise I want to be able to create Repos and project folders in one go and add changes to the repo's svn conf files.

I want to check if there is already an existing repository and if the name=passw line is already added to the passw db.

I did use:

svnlook youngest /Volumes/Development/_svnRepo/SSHToolNew 2>&1 | grep "No such file or directory" -c

to check for the error message returned by svnlook

svnlook: Can't open file '/Volumes/Development/_svnRepo/SSHToolNew/format': No such file or directory

and want to continue doing my stuff when the result is bigger then 0, otherwise create the repo first with some options.



With the following info

/Volumes/Development/_svnRepo/SSHTools exists
/Volumes/Development/_svnRepo/SSHToolNew doesn't exists


using ( typed in the sh )

svnlook youngest /Volumes/Development/_svnRepo/SSHToolNew 2>&1 | grep "No such file or directory" -c
1
echo "rv:" $?
1

gives as result 1 in the shell and when using echo "rv:" $?


however

svnlook youngest /Volumes/Development/_svnRepo/SSHToolNew 2>&1 | grep "No such file or directory" -c &> /dev/null
echo "rv:" $?
0

gives 0 as result.

And when the folder do exists it return the opposite!?

Just to understands the happening. Why the difference with &> /dev/null ?
What do I mis here?

Posted on Jan 10, 2010 6:17 AM

Reply
3 replies

Jan 10, 2010 7:35 AM in response to Obj-D

What do you want to happen with "&> /dev/null"? It seems like you want just "> /dev/null". There seems to be a special meaning to "&>":


Redirecting Standard Output and Standard Error
Bash allows both the standard output (file descriptor 1) and the standard error output (file
descriptor 2) to be redirected to the file whose name is the expansion of word with this con-
struct.
There are two formats for redirecting standard output and standard error:
&>word
and
&word

Of the two forms, the first is preferred. This is semantically equivalent to
word 2>&1

Jan 10, 2010 8:23 AM in response to etresoft

Hi Thanks you for your reply,

I want that the result goes into a var so that I can compare it in an 'if' statement.

If I leave & out then I get the following same result

bash-3.2$ svnlook youngest /Volumes/Development/_svnRepo/SSHToolNew 2>&1 | grep "No such file or directory" -c > /dev/null
bash-3.2$ echo "rv: "$?
rv: 0

It should be one ( 1 ) because the result count is one. Or am I wrong?

So basicly, why is it changing the result? or is $? not the result of my line?

What is the best way to check if f.e a command is failed like the one I use in an if statement? Can I move the result directly into a var, something like?

bash-3.2$ svnlook youngest /Volumes/Development/_svnRepo/SSHToolNew 2>&1 | grep "No such file or directory" -c | MyVar=$? ( or whatever needed )



Thanks again

Jan 10, 2010 8:36 AM in response to Obj-D

Obj-D wrote:
It should be one ( 1 ) because the result count is one. Or am I wrong?


I was afraid you would ask. I am not a bash expert. I do know that you aren't getting any "counts" out. You just get result codes from the processes and 0 is good, anything else is failure. If you want counts, you'll have to pipe the result into "wc -l" or something.

There are several people who really know bash, hopefully they can respond. I would just do it in Perl myself. I understand Perl much better than bash.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

/dev/null changes result, why? ( How to know if svn repository exists )

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.