I am working on a bash script that I would like to work for several types of VCS. I am thinking of testing if a directory is a repo for a system by running a typical info command and checking the return code, success or error. In pseudo code:
if a svn command succeded;
Then run svn commands
elif a darcs command succeded;
Then run darcs commands
elif a mercurial command succeded;
then run hg commands
else
something else
fi
I can run a command, e.g.
darcs show repo
and use $?
to get its return code.
My question is: is there a neat way to run and return the return code number in one line? for example
if [ 0 -eq `darcs show repo`$? ];
Or do I have to define a function?
An added requirement is that both stderr and stdout should be printed.