Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-06-2013, 03:32 PM   #1
LQ Newbie
Registered: Nov 2012
Posts: 9

Rep: Reputation: Disabled
if statement options in bash script

I have a bash script (not mine) that is generating some errors. I'm trying to fix that but there is a section that I do not understand.

snpsOALib=`OA_MODE=opt $OA_ROOT/bin/oaGetLibPath`
if [ $? != 0 ] || [ ! -d $snpsOALib ]; then
    echo "Error: Incomplete installation. OpenAccess is missing or improperly installed."
    exit 1
export OA_ROOT
$OA_ROOT is a directory
I don't know what $? is .. I thought it's a variable but that is the only one written in the file(it is not defined before,neither $? nor ?).

now what does this If statement mean ?? can somebody explain ??
Old 08-06-2013, 03:42 PM   #2
Senior Member
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
$? is the exit code of the last command
when exit code is 0 it means no error, and none-zero code is an Error

try it with a few things

true;echo $?
false;echo $?
ffaallssee;echo $?

so what is happening which with the script is
snpsOALib=`OA_MODE=opt $OA_ROOT/bin/oaGetLibPath`
# set snpsOALib as output of command "OA_MODE=opt $OA_ROOT/bin/oaGetLibPath"
if [ $? != 0 ] || [ ! -d $snpsOALib ]; then
# if last command gave error ( not equal to 0 ) OR $snpsOALib is not a directory
    echo "Error: Incomplete installation. OpenAccess is missing or improperly installed."
# above prints error msg, below exits the script ( with exit code 1 )
    exit 1
export OA_ROOT

Last edited by Firerat; 08-06-2013 at 03:44 PM. Reason: don't ask me where which came from
1 members found this post helpful.
Old 08-06-2013, 03:47 PM   #3
LQ 5k Club
Registered: Jan 2011
Location: Nowhere near you, thank God.
Distribution: OSX Sierra
Posts: 8,576
Blog Entries: 15

Rep: Reputation: Disabled
Open Audit?

err. n/m
Old 08-07-2013, 02:14 AM   #4
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,411

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
Incidentally, '!=' is the wrong operator for a numeric comparison; it should be '-ne', or use (( )) instead of [[ ]]


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 10:46 AM
[SOLVED] [bash] if statement options. RaptorX Programming 9 08-17-2009 01:30 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 07:00 AM
bash case statement with multiple command line options pwc101 Programming 16 06-01-2007 12:43 PM
problem with if statement in bash script crewblunts Programming 3 03-11-2006 01:38 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:29 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration