LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 08-06-2013, 02:32 PM   #1
Ewais
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.

Code:
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
fi
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, 02:42 PM   #2
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
$? 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
Code:
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
fi
export OA_ROOT

Last edited by Firerat; 08-06-2013 at 02:44 PM. Reason: don't ask me where which came from
 
1 members found this post helpful.
Old 08-06-2013, 02:47 PM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Open Audit?

err. n/m
 
Old 08-07-2013, 01:14 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Incidentally, '!=' is the wrong operator for a numeric comparison; it should be '-ne', or use (( )) instead of [[ ]] http://tldp.org/LDP/abs/html/comparison-ops.html:
 
  


Reply



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 09:46 AM
[SOLVED] [bash] if statement options. RaptorX Programming 9 08-17-2009 12:30 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
bash case statement with multiple command line options pwc101 Programming 16 06-01-2007 11:43 AM
problem with if statement in bash script crewblunts Programming 3 03-11-2006 12:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:16 AM.

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