Skip to main content
edited tags; edited title
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k

Bash script to detect the version control system by testing if a command has run correctlyreturn status

added a requirement
Source Link
Niall Murphy
  • 305
  • 1
  • 3
  • 9

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.

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?

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.

Source Link
Niall Murphy
  • 305
  • 1
  • 3
  • 9

Bash script testing if a command has run correctly

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?