LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 03: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, 03:42 PM   #2
Firerat
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
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 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
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,667
Blog Entries: 10

Rep: Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076Reputation: 2076
Open Audit?

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

Rep: Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328Reputation: 2328
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


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


All times are GMT -5. The time now is 07:17 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration