what does if[$? -ne 0] mean in unix | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

what does if[$? -ne 0] mean in unix

Shell Programming and Scripting


Tags
linux, solaris

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-15-2006
shree shree is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 15 June 2006, 12:20 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
what does if[$? -ne 0] mean in unix

Hi,

what does this mean in unix
if [$? -ne 0]

I understand ne is not equal to zero but how abt $?

Also, what does exit 1 or exit 0 mean.

Last edited by shree; 06-15-2006 at 12:16 PM..
Sponsored Links
    #2  
Old 06-15-2006
steweston steweston is offline
Registered User
 
Join Date: May 2006
Last Activity: 30 June 2006, 10:33 AM EDT
Location: Vancouver, BC
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
if [$? -ne 0]

$? is the return code form a previous command or function
in unix, 0 is the standard return code for a successful completion

if [$? -ne 0]
The whole line means

'if the previous return code was not equal to 0 ' ....

It will then be followed by

then
statement # do something
(optional) else
(optional) statement # do something else
fi # closure of the 'if' conditional



Steve
The Following User Says Thank You to steweston For This Useful Post:
sriniv666 (05-24-2011)
Sponsored Links
    #3  
Old 06-15-2006
shree shree is offline
Registered User
 
Join Date: Jun 2006
Last Activity: 15 June 2006, 12:20 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Steve.

but another question.

I have a FTP process happening and the file from remote m/c is FTPed to local m/c's file called result file, now how can I check if the FTP process was fine and if a result file was created.
    #4  
Old 06-15-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
AFK
 
Join Date: Dec 2004
Last Activity: 28 July 2014, 9:39 AM EDT
Location: UK
Posts: 2,351
Thanks: 0
Thanked 6 Times in 6 Posts
This is not a technical forum. Mods please move this thread to the appropriate forum.
Sponsored Links
    #5  
Old 07-20-2008
naughty21 naughty21 is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 11 February 2009, 8:53 PM EST
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
thanks for the information.....but can u tell me what is the previous return code............
is the command or code above the if statement ?

im very new to shell scripting..........any help ?

and also can u tell me what does this means if [ $# -ne 3 ];
Sponsored Links
    #6  
Old 07-21-2008
danmero danmero is offline Forum Advisor  
 
Join Date: Nov 2007
Last Activity: 12 October 2014, 10:11 AM EDT
Location: H3X
Posts: 2,151
Thanks: 10
Thanked 117 Times in 110 Posts
Quote:
Originally Posted by naughty21 View Post
...but can u tell me what is the previous return code............
is the command or code above the if statement ?
Is the exit code of the previous command.

Quote:
Originally Posted by naughty21 View Post
and also can u tell me what does this means if [ $# -ne 3 ];
If the number of arguments is not equal to 3 ... do something.

You should begin by reading An Introduction To Shell Programming
... and when you finish proceed to: http://www.unix.com/answers-frequent...tutorials.html

Last edited by danmero; 07-21-2008 at 01:04 AM.. Reason: add link to tutorials
Sponsored Links
    #7  
Old 07-21-2008
ynilesh's Avatar
ynilesh ynilesh is offline
Registered User
 
Join Date: Oct 2007
Last Activity: 7 April 2009, 7:39 AM EDT
Location: Bangalore, India.
Posts: 222
Thanks: 0
Thanked 0 Times in 0 Posts
Hello Shree,

To verify whether data copying is happened properly, you can use "md5sum" check. get the original file md5sum and again get it after copying it to local machine. Compare them. If same then file has been copied properly else issue while copying file.

And to check if result file has been created use,

if [ -e "filename" ]
then
echo "File exist"
else
echo "File does not exist"
fi

Please let me know if u need more help.

- nilesh

Last edited by ynilesh; 07-21-2008 at 12:49 AM..
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How does unix system administration, unix programming, unix network programming differ? thulasidharan2k UNIX for Dummies Questions & Answers 0 06-09-2011 09:40 AM
Running UNIX commands remotely in Windows box from Unix box avoid entering password D.kalpana UNIX for Dummies Questions & Answers 1 04-20-2007 05:24 AM
Unix History Question: Why are filenames/dirnames case sentsitive in Unix? deckard UNIX for Dummies Questions & Answers 3 03-26-2005 12:59 PM



All times are GMT -4. The time now is 07:57 AM.